Skip to content

Commit d05af96

Browse files
committed
Solve Knapsack
1 parent 678522b commit d05af96

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

Knapsack.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
const int N = 1e6, NT = N + 2, MAXW = 1e6;
6+
7+
int DP[MAXW + 2], m[N], w[N];
8+
9+
signed main() {
10+
ios_base::sync_with_stdio(0);
11+
cin.tie(0);
12+
int n, W;
13+
cin >> n >> W;
14+
15+
for (int i = 0; i <= W; ++i)
16+
DP[i] = 0;
17+
for (int j = 1; j <= n; ++j)
18+
for (int i = W - m[j]; i >= 0; --i)
19+
DP[i + m[j]] = max(DP[i + m[j]], DP[i] + w[j]);
20+
return 0;
21+
}

Plecak.cpp

-16
This file was deleted.

0 commit comments

Comments
 (0)