码迷,mamicode.com
首页 > 移动开发 > 详细

nyoj 苹果(01背包)

时间:2015-03-22 10:36:48      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

裸题

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<string>
 6 #include<queue>
 7 #include<algorithm>
 8 #include<map>
 9 #include<iomanip>
10 #include<climits>
11 #include<string.h>
12 #include<cmath>
13 #include<stdlib.h>
14 #include<vector>
15 #include<stack>
16 #include<set>
17 #define INF 1e7
18 #define MAXN 100010
19 #define maxn 1000010
20 #define Mod 1000007
21 #define N 1010
22 using namespace std;
23 typedef long long LL;
24 
25 int T, n, V;
26 int dp[N];
27 int c[N], w[N];
28 
29 void run()
30 {
31     for (int i = 1; i <= n; ++i) {
32         cin >> c[i] >> w[i];
33     }
34     memset(dp, 0, sizeof(dp));
35     for (int i = 1; i <= n; ++i)
36         for (int j = V; j >= c[i]; --j)
37             dp[j] = max(dp[j], dp[j - c[i]] + w[i]);
38     cout << dp[V] << endl;
39 }
40 
41 int main()
42 {
43     while (cin >> n >> V, n+V)
44         run();
45     //system("pause");
46     return 0;
47 }
View Code

 

nyoj 苹果(01背包)

标签:

原文地址:http://www.cnblogs.com/usedrosee/p/4356793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!