标签:title col pid color ted its lap class nsis
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1114
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27563 Accepted Submission(s): 13934
1 //一道纯粹的完全背包。 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cmath> 6 #include <algorithm> 7 #include <vector> 8 #include <queue> 9 #include <stack> 10 #include <map> 11 #include <string> 12 #include <set> 13 #define ms(a,b) memset((a),(b),sizeof((a))) 14 using namespace std; 15 typedef long long LL; 16 const double EPS = 1e-8; 17 const int INF = 2e9; 18 const LL LNF = 2e18; 19 const int MAXN = 1e3+10; 20 21 int wei[MAXN], val[MAXN], dp[10010]; 22 23 int main() 24 { 25 int T, n; 26 scanf("%d", &T); 27 while(T--) 28 { 29 int E, F, W; 30 scanf("%d%d", &E, &F); 31 W = F - E; 32 33 scanf("%d", &n); 34 for(int i = 1; i<=n; i++) 35 scanf("%d%d", &val[i], &wei[i]); 36 37 for(int i = 1; i<= W; i++) 38 dp[i] = INF; 39 dp[0] = 0; 40 for(int i = 1; i<=n; i++) 41 for(int j = 1; j<=W; j++) 42 if(j>=wei[i] && dp[j-wei[i]]!=INF ) 43 dp[j] = min(dp[j], dp[j-wei[i]]+val[i]); 44 45 if(dp[W]!=INF) 46 printf("The minimum amount of money in the piggy-bank is %d.\n", dp[W]); 47 else 48 printf("This is impossible.\n"); 49 } 50 }
标签:title col pid color ted its lap class nsis
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7624554.html