标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22659 Accepted Submission(s): 6892
1 //2016.8.20 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 7 using namespace std; 8 9 double A, B, C, money[50], dp[50];//money[i]表示能报销的账单i的金额, dp[i]报销前i张所得到的最大金额 10 11 int main() 12 { 13 double Q, price; 14 int n, m, tot; 15 char Type; 16 bool fg; 17 while(cin>>Q>>n&&n) 18 { 19 tot = 0; 20 memset(money, 0, sizeof(money)); 21 memset(dp, 0, sizeof(dp)); 22 while(n--) 23 { 24 scanf("%d", &m); 25 A = B = C = 0; 26 fg = true; 27 for(int i = 0; i < m; i++) 28 { 29 scanf(" %c:%lf", &Type, &price); 30 if(Type!=‘A‘&&Type!=‘B‘&&Type!=‘C‘||price>600) 31 fg = false; 32 if(Type==‘A‘)A+=price; 33 else if(Type==‘B‘)B+=price; 34 else if(Type==‘C‘)C+=price; 35 } 36 if(fg&&A<=600&&B<=600&&C<=600&&A+B+C<=1000) 37 money[tot++] = A+B+C; 38 } 39 for(int i = 0; i <= tot; i++) 40 for(int j = tot; j >= 1; j--) 41 if(j==1||dp[j-1]>0&&dp[j-1]+money[i]<=Q) 42 dp[j] = max(dp[j], dp[j-1]+money[i]); 43 44 double ans = 0; 45 for(int i = 1; i <= tot; i++) 46 if(ans<dp[i]) 47 ans = dp[i]; 48 49 printf("%.2lf\n", ans); 50 } 51 52 return 0; 53 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5791452.html