Optimize and Format Knapsack Memoization Algorithm (#5685)

This commit is contained in:
PANKAJ PATWAL
2024-10-12 12:41:25 +05:30
committed by GitHub
parent b81671e66d
commit e38611e9db
2 changed files with 20 additions and 6 deletions

View File

@ -31,4 +31,19 @@ public class KnapsackMemoizationTest {
int capacity = 50;
assertEquals(220, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
void test4() {
int[] weight = {1, 2, 3};
int[] value = {10, 20, 30};
int capacity = 0;
assertEquals(0, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
void test5() {
int[] weight = {1, 2, 3, 8};
int[] value = {10, 20, 30, 40};
int capacity = 50;
assertEquals(100, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
}