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 |
g++wa, c++ac, 不解。。。我自己调试什么都是用g++#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define N 800 #define inf 10000000 struct node { bool status[200]; int plus; int sump; int sumd; }; struct node dp[20][N]; int main() { int i, j, k, r, n, m, round = 0; int defence[200], prosecution[200], plus[200], sub[200]; int index, size, dsize; struct node init; memset(&init, 0, sizeof(init)); while(scanf("%d%d", &n, &m), n != 0) { size = m * 20; dsize = size + size; for(i = 0; i < dsize; ++i) { dp[0][i].plus = inf; } for(i = 0; i < n; ++i) { scanf("%d%d", &prosecution[i], &defence[i]); sub[i] = prosecution[i] - defence[i]; plus[i] = prosecution[i] + defence[i]; index = sub[i] + size; if(dp[0][index].plus == inf || plus[i] > dp[0][index].plus) { dp[0][index] = init; dp[0][index].plus = plus[i]; dp[0][index].status[i] = true; dp[0][index].sump = prosecution[i]; dp[0][index].sumd = defence[i]; } } for(i = 1; i < m; ++i) { r = i - 1; for(j = 0; j < dsize; ++j) { dp[i][j].plus = inf; } for(j = 0; j < dsize; ++j) { if(dp[r][j].plus != inf) { for(k = 0; k < n; ++k) { if(dp[r][j].status[k] == true) continue; index = j + sub[k]; if(dp[i][index].plus == inf || dp[r][j].plus + plus[k] > dp[i][index].plus) { dp[i][index] = dp[r][j]; dp[i][index].status[k] = true; dp[i][index].sump += prosecution[k]; dp[i][index].sumd += defence[k]; dp[i][index].plus = dp[r][j].plus + plus[k]; } } } } } for(r = m - 1, i = j = size; i < dsize ; ++i, --j) { if(dp[r][i].plus != inf) { index = i; break; } if(dp[r][j].plus != inf) { index = j; break; } } if(dp[r][i].plus != inf && dp[r][j].plus != inf) { if(dp[r][i].plus > dp[r][j].plus) index = i; else index = j; } printf("Jury #%d\n", ++round); printf("Best jury has value %d for prosecution and value %d for defence:\n", dp[r][index].sump, dp[r][index].sumd); for(i = 0; i < n; ++i) if(dp[r][index].status[i] == true) printf(" %d", i + 1); printf("\n\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator