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 |
求高手一直知道哪里错了#include <stdio.h> #include <string.h> #include <math.h> int main() { int dp[10100][6]; int P, coin[4]; int c[4] = {1, 5, 10, 25}; int i, j, k, t, l; while(scanf("%d", &P) != EOF) { for(i = 0;i < 4;i ++ )scanf("%d", &coin[i]); if(P == 0) { break; } memset(dp, 0, sizeof(dp)); for(i = 0;i < 4;i ++ ) { for(k = c[i];k <= P;k ++ ) { if(dp[k - c[i]][0] + c[i] > dp[k][0] && dp[k- c[i]][i + 1] < coin[i]) { dp[k][0] = dp[k - c[i]][0] + c[i]; for(l = 1;l <= 4;l ++ ) { if(l == i + 1)dp[k][l] = dp[k - c[i]][l] + 1; else dp[k][l] = dp[k - c[i]][l]; } dp[k][5] = dp[k - c[i]][5] + 1; } else if(dp[k - c[i]][0] + c[i] == dp[k][0]) { if(dp[k - c[i]][5] > dp[k][5]) { for(l = 1;l <= 4;l ++ ) { dp[k][l] = dp[k - c[i]][l]; } dp[k][5] = dp[k - c[i]][5]; } } } } if(dp[P][0] == P) { printf("Throw in %d cents, %d nickels, %d dimes, and %d quarters.\n", dp[P][1], dp[P][2], dp[P][3], dp[P][4]); } else printf("Charlie cannot buy coffee.\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator