标签:des style blog http color io os ar java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12466 Accepted Submission(s): 6312
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define min(a,b) a<b?a:b #define INF 0x7ffffff #define N 10010 int n,s; int dp[N]; int v[N],w[N]; //算了,统一一下,n代表种类,s代表总容量,v代表价值,w代表重量 int main() { int T,i,j; scanf("%d",&T); while(T--) { int s1,s2; scanf("%d%d%d",&s1,&s2,&n); s=s2-s1; for(i=1;i<=n;i++) { scanf("%d%d",&v[i],&w[i]); } for(i=1;i<=N;i++) { dp[i]=INF; } dp[0]=0; for(i=1;i<=n;i++) { for(j=w[i];j<=s;j++) { dp[j]=min(dp[j],dp[j-w[i]]+v[i]); } } if(dp[s]!=INF) cout<<"The minimum amount of money in the piggy-bank is "<<dp[s]<<‘.‘<<endl; else cout<<"This is impossible.\n"; } return 0; }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/hate13/p/4050378.html