Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
枚举就好了。枚举第一组包含多少个数字,然后嘗试把后面的数列分成同等和的组別。 複杂度O(N^2),不过数据太弱了,0ms过 代码如下︰ #include <iostream> #include <cstdio> using namespace std; int main(){ int p, m, d[10010], i, j, z, minsum, sum; scanf("%d", &p); while(p--){ scanf("%d%d", &z, &m); for (i=0; i<m; i++) scanf("%d", d+i); for (i=0, minsum=0; i<m; i++){ minsum+=d[i]; for (j=i+1, sum=0; j<m; j++){ sum+=d[j]; if (sum>minsum) break; if (sum==minsum) sum=0; } if (j==m && sum==0) break; } printf("%d %d\n", z, minsum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator