标签:bank cstring into color var moved ssi memory sim
3 10 110 2 1 1 30 50 10 110 2 1 1 50 30 1 6 2 10 3 20 4
The minimum amount of money in the piggy-bank is 60. The minimum amount of money in the piggy-bank is 100. This is impossible.
思路:裸的完全背包
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int INF=0x3f3f3f3f; 7 const int maxn = 1000; 8 int weight[maxn], value[maxn]; 9 int dp[510][10100]; 10 int main() 11 { 12 int n; 13 scanf("%d",&n); 14 while(n--) 15 { 16 memset(weight,0,sizeof(weight)); 17 memset(value,0,sizeof(value)); 18 memset(dp,INF,sizeof(dp)); 19 int v1,v2,v; 20 scanf("%d%d",&v1,&v2); 21 v=v2-v1; 22 int m; 23 scanf("%d",&m); 24 for(int i=1; i<=m; i++) 25 scanf("%d%d",&value[i],&weight[i]); 26 dp[0][0]=0; 27 for(int i=1; i<=m; i++) 28 { 29 for(int j=0; j<=v; j++) 30 dp[i][j]=dp[i-1][j]; 31 for(int j=weight[i]; j<=v; j++) 32 dp[i][j]=min(dp[i][j], dp[i][j-weight[i]] + value[i] ) ; 33 34 } 35 if(dp[m][v]!=INF) 36 printf("The minimum amount of money in the piggy-bank is %d.\n",dp[m][v]); 37 else 38 printf("This is impossible.\n"); 39 } 40 return 0; 41 }
标签:bank cstring into color var moved ssi memory sim
原文地址:http://www.cnblogs.com/xcantaloupe/p/7352120.html