标签:print out ever space tar ott not oid unp
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int INF = 1 << 30; 4 int main() 5 { 6 int T,E,F,N,P,W; 7 int dp[50005]; 8 while(cin>>T) 9 { 10 while(T--) 11 { 12 dp[0] = 0; 13 scanf("%d %d",&E,&F);/*E为weight of an empty pig ,F为装满硬币的存储罐的重量*/ 14 scanf("%d",&N); /*硬币的种类*/ 15 for(int i = 1; i <= F; i++) 16 dp[i] = INF; 17 for(int i = 0; i < N; i++) 18 { 19 scanf("%d %d",&P,&W); /*P为硬币的面值 W为硬币的重量*/ 20 for(int j = W; j <= F-E; j++) 21 dp[j] = min(dp[j],dp[j-W]+P); 22 } 23 if(dp[F-E] == INF ) cout<<"This is impossible."<<endl; 24 else cout<<"The minimum amount of money in the piggy-bank is "<<dp[F-E]<<"."<<endl; 25 } 26 } 27 28 return 0; 29 }
标签:print out ever space tar ott not oid unp
原文地址:http://www.cnblogs.com/jj81/p/7349753.html