标签:
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 int E,F,W; 6 int v[501],w[501],p[10003]; 7 int n; 8 void dp() 9 { 10 int i,j; 11 for(i=1;i<=n;i++) 12 for(j=w[i];j<=W;j++) 13 p[j]=min(p[j],p[j-w[i]]+v[i]); 14 } 15 int main() 16 { 17 int i,j; 18 int T; 19 cin>>T; 20 while(T--) 21 { 22 cin>>E>>F; 23 W=F-E; 24 cin>>n; 25 for(i=1;i<=W;i++) 26 p[i]=9999999; 27 for(i=1;i<=n;i++) 28 cin>>v[i]>>w[i]; 29 p[0]=0; 30 dp(); 31 if(p[W]==9999999) 32 cout<<"This is impossible."<<endl; 33 else 34 cout<<"The minimum amout of money in the piggy-bank is "<<p[W]<<"."<<endl; 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4540148.html