01背包

最基础的DP

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "string"
 4 using namespace std;
 5 #define MAXN 222222
 6 int c[MAXN],v[MAXN];
 7 int dp[MAXN];
 8 int main()
 9 {
10     int n,C;
11     cin >> n >> C;
12     for (int i = 0;i < n; ++ i)
13         cin >> c[i] >> v[i];
14     for (int i = 0;i < n ; ++ i)
15         for (int w = C;w >= 0 ; -- w)
16             if (w-c[i] >= 0)
17             dp[w] = max(dp[w],dp[w-c[i]] + v[i]);
18     cout << dp[C] << endl;
19     return 0;
20 }
代码君

 

posted @ 2014-12-13 23:32  UsedRose  阅读(125)  评论(0编辑  收藏  举报