feat: added alternative python solutions.
This commit is contained in:
11
knapsack-zero-one/src/alternative-ac.py
Normal file
11
knapsack-zero-one/src/alternative-ac.py
Normal file
@@ -0,0 +1,11 @@
|
||||
N, W = map(int, input().split())
|
||||
|
||||
dp = [0] * (W + 1)
|
||||
|
||||
for _ in range(N):
|
||||
w, v = map(int, input().split())
|
||||
|
||||
for j in range(W, w - 1, -1):
|
||||
dp[j] = max(dp[j], dp[j - w] + v)
|
||||
|
||||
print(dp[W])
|
||||
@@ -6,7 +6,7 @@ using namespace std;
|
||||
const int MIN_N = 1;
|
||||
const int MAX_N = 100;
|
||||
const int MIN_W = 1;
|
||||
const int MAX_W = 1e5;
|
||||
const int MAX_W = 1e4;
|
||||
const int MIN_V = 1;
|
||||
const int MAX_V = 1e9;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
int N = inf.readInt(1, 100, "N");
|
||||
inf.readSpace();
|
||||
int W = inf.readInt(1, 1e5, "W");
|
||||
int W = inf.readInt(1, 1e4, "W");
|
||||
inf.readEoln();
|
||||
for (int i = 0; i < N; i++) {
|
||||
inf.readInt(1, W, "wi");
|
||||
|
||||
Reference in New Issue
Block a user