Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d3754c

Browse files
Knapsack (Repetition of items allowed)
1 parent 3346cb2 commit 9d3754c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Amit Bansal - @amitbansal7 */
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
int main()
5+
{
6+
int v[] = {60, 100, 120, 150};
7+
int w[] = {10, 20, 30, 20};
8+
const int c = 60;
9+
int itm = sizeof(v) / sizeof(v[0]);
10+
int DP[c + 1] = {0};
11+
12+
for (int i = 0; i <= c; i++)
13+
for (int j = 0; j < itm; j++)
14+
if (w[j] <= i)
15+
DP[i] = max(DP[i], DP[i - w[j]] + v[j]);
16+
17+
printf("%d\n", DP[c]);
18+
19+
return 0;
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /