Skip to content

Commit ea230cf

Browse files
committed
fix: Make it look like C++ code
1 parent 63b60d2 commit ea230cf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

dynamic_programming/0_1_knapsack.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,24 @@ int Knapsack(int capacity, int n, int weight[], int value[]) {
3131
int res[20][20];
3232
for (int i = 0; i < n + 1; ++i) {
3333
for (int j = 0; j < capacity + 1; ++j) {
34-
if (i == 0 || j == 0)
34+
if (i == 0 || j == 0) {
3535
res[i][j] = 0;
36-
else if (weight[i - 1] <= j)
36+
} else if (weight[i - 1] <= j) {
3737
res[i][j] = max(value[i - 1] + res[i - 1][j - weight[i - 1]],
38-
res[i - 1][j]);
39-
else
38+
res[i - 1][j]);
39+
} else {
4040
res[i][j] = res[i - 1][j];
41+
}
4142
}
4243
}
4344
// Print(res, n, capacity, capacity);
4445
// cout<<"\n";
4546
return res[n][capacity];
4647
}
48+
49+
/**
50+
* Main function
51+
*/
4752
int main() {
4853
int n;
4954
std::cout << "Enter number of items: ";

0 commit comments

Comments
 (0)