We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 47f72a0 commit 7f464d8Copy full SHA for 7f464d8
1 file changed
DynamicProgram/lint125-backpack-ii.md
@@ -0,0 +1,23 @@
1
+---
2
+title: lint125-backpack-ii
3
+tags: 新建,模板,小书匠
4
+grammar_cjkRuby: true
5
6
+
7
8
+# problem
9
+[lint125-backpack-ii](http://www.lintcode.com/en/problem/backpack-ii/)
10
+# solution
11
+这是0-1背包问题的解法
12
+```
13
+ int backPackII(int m, vector<int> A, vector<int> V) {
14
+ // write your code here
15
+ vector<int> result(m+1, 0);
16
+ int len = A.size();
17
+ for (int i = 0; i< len; i++)
18
+ for (int j = m; j > 0; j--)
19
+ if (A[i] <= j && result[j] < result[j - A[i]] + V[i])
20
+ result[j] = result[j - A[i]] + V[i];
21
+ return result[m];
22
+ }
23
0 commit comments