标签:
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <ctime> 5 #include <iostream> 6 #include <algorithm> 7 #include <set> 8 #include <vector> 9 #include <sstream> 10 #include <queue> 11 #include <typeinfo> 12 #include <fstream> 13 #include <map> 14 #include <stack> 15 using namespace std; 16 #define INF 1000000 17 typedef long long ll; 18 const int maxn=510; 19 struct money{ 20 int p,w; 21 }mm[maxn]; 22 int dp[10010]; 23 int main() 24 { 25 int t; 26 scanf("%d",&t); 27 while(t--){ 28 int e,f; 29 scanf("%d%d",&e,&f); 30 int n; 31 scanf("%d",&n); 32 for(int i=0;i<n;i++){ 33 scanf("%d%d",&mm[i].p,&mm[i].w); 34 } 35 int tot=f-e; 36 for(int i=1;i<=tot;i++) dp[i]=INF; 37 dp[0]=0; 38 for(int i=0;i<n;i++){ 39 for(int v=mm[i].w;v<=tot;v++){ 40 dp[v]=min(dp[v],dp[v-mm[i].w]+mm[i].p); 41 } 42 } 43 if(dp[tot]!=INF) printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f-e]); 44 else printf("This is impossible.\n"); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/RRirring/p/4719572.html