| ||||||||||
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 |
P1882,help!The second of the example,my answer is always: "max coverage = 544 : 1 15 52 67 99",but the standard answer is: "max coverage = 409 : 1 7 16 31 88". Is it because I don`t understand the meaning of "the maximal coverage"? I have no idea. This is my code(C++): #include<cstdio> const int maxn = 15; const int maxm = 1e3 + 10; int stamps[maxn][maxn], f[maxm]; int S, n; void calc(int& x, int& y, int cur); int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } int main() { while(scanf("%d", &S) == 1 && S) { scanf("%d", &n); for(int k = 1; k <= n; k++) { scanf("%d", &stamps[k][0]); for(int i = 1; i <= stamps[k][0]; i++) scanf("%d", &stamps[k][i]); } int ans = -1, col, M; for(int k = 1; k <= n; k++) { int res, _m; calc(res, _m, k); printf("res = %d m = %d\n", res, _m); if(res < ans) continue; if(res > ans || (stamps[col][0] > stamps[k][0]) || (stamps[col][0] == stamps[k][0] && _m < M)) { ans = res; col = k; M = _m; } } printf("max coverage = %d :", ans); for(int i = 1; i <= stamps[col][0]; i++) printf(" %d", stamps[col][i]); printf("\n"); } return 0; } void calc(int& x, int& y, int cur) { for(int i = 1; i < maxm; i++) f[i] = 1e9; f[0] = 0; y = -1; for(int i = 1; i <= stamps[cur][0]; i++) { y = max(y, stamps[cur][i]); for(int j = stamps[cur][i]; j < maxm; j++) if(f[j - stamps[cur][i]] < S) f[j] = min(f[j], f[j - stamps[cur][i]] + 1); } // for(int i = 0; i < 10; i++) printf("!%d ", f[i]); // printf("\n"); x = -1; for(int i = 1; i < maxm; i++) { if(f[i] > S) continue; int j; for(j = i; (j + 1) < maxm && f[j + 1] <= S; j++); x = max(x, j - i + 1); i = j; } return; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator