标签:
Value | Annual interest |
4000 3000 |
400 250 |
1 10000 4 2 4000 400 3000 250
14050
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn = 50010; 6 int dp[maxn],c[maxn],v[maxn]; 7 int main() { 8 int T,m,year,n; 9 scanf("%d",&T); 10 while(T--) { 11 scanf("%d %d %d",&m,&year,&n); 12 for(int i = 0; i < n; ++i) { 13 scanf("%d %d",v+i,c+i); 14 v[i] /= 1000; 15 } 16 int sum = 0; 17 for(int i = 0; i < year; ++i) { 18 memset(dp,0,sizeof dp); 19 sum = m/1000; 20 for(int j = 0; j < n; ++j) { 21 for(int k = v[j]; k <= sum; ++k) 22 dp[k] = max(dp[k],dp[k-v[j]] + c[j]); 23 } 24 m += dp[sum]; 25 } 26 printf("%d\n",m); 27 } 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4442410.html