标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 10087 | Accepted: 3539 |
Description
Value | Annual interest |
4000 3000 |
400 250 |
Input
Output
Sample Input
1 10000 4 2 4000 400 3000 250
Sample Output
14050
Source
#include<iostream> #include<stdio.h> #include<cstring> using namespace std; const int maxx = 105; //long long dp[maxx][maxx]; int dp[100030]; int bag; int w[maxx],v[maxx]; int kind; int year; int get() { memset(dp,0,sizeof(dp)); /* for(int i=1;i<=kind;i++) { for(int j=0;j<=bag;j++) { for(int k=0;k*w[i]<=j;k++) { dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]*k]+v[i]*k); } } } bag=dp[kind][bag]; return bag;*/ for(int i=1;i<=kind;i++) { for(int j=w[i];j<=bag;j++) { dp[j]=max(dp[j],dp[j-w[i]]+v[i]); } } return dp[bag]; } int main() { int t; scanf("%d",&t); while(t--) { int ans=0; scanf("%d%d",&bag,&year); scanf("%d",&kind); ans=bag; bag/=1000; for(int i=1;i<=kind;i++) { scanf("%d%d",&w[i],&v[i]); w[i]/=1000; } for(int k=0;k<year;k++) { ans+=get(); bag=(ans/1000); } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/superxuezhazha/p/5746807.html