diff --git a/01 knapsack/01 knapsack bottom up.py b/01 knapsack/01 knapsack bottom up.py deleted file mode 100644 index 566479b1..00000000 --- a/01 knapsack/01 knapsack bottom up.py +++ /dev/null @@ -1,21 +0,0 @@ -def knapsack(W, wt, val, n): - - dp = [[-1 for x in range(W + 1)] for y in range(n + 1)] - for x in range(n + 1): - for y in range(W + 1): - if x == 0 or y == 0: - dp[x][y] = 0 - - for x in range(1, n + 1): - for y in range(1, W + 1): - if wt[x - 1] <= y: - dp[x][y] = max(val[x - 1] + dp[x - 1][y - wt[x - 1]], dp[x - 1][y]) - else: - dp[x][y] = dp[x - 1][y] - return dp[-1][-1] - -n = 3 -W = 4 -wt = [4, 5, 1] -val = [1, 2, 3] -print(knapsack(W, wt, val, n)) \ No newline at end of file diff --git a/01 knapsack/01 knapsack recursion memoization dictionary.py b/01 knapsack/01 knapsack recursion memoization dictionary.py deleted file mode 100644 index f3c23172..00000000 --- a/01 knapsack/01 knapsack recursion memoization dictionary.py +++ /dev/null @@ -1,23 +0,0 @@ -def knapSack(self,W, wt, val, n): - def knapsack(W, wt, val, n, memo = {}): - if (n, W) in memo: - return memo[(n, W)] - - if n == 0 or W == 0: - return 0 - - elif wt[n - 1] <= W: - memo[(n, W)] = max(val[n - 1] + knapsack(W - wt[n - 1], wt, val, n - 1, memo), knapsack(W, wt, val, n - 1, memo)) - return memo[(n, W)] - - else: - memo[(n, W)] = knapsack(W, wt, val, n - 1, memo) - return memo[(n, W)] - - return knapsack(W, wt, val, n) - -N = 3 -W = 3 -values = [1,2,3] -weight = [4,5,6] -print(knapSack(W, weight, values, N)) \ No newline at end of file diff --git a/01 knapsack/01 knapsack recursion memoization table.py b/01 knapsack/01 knapsack recursion memoization table.py deleted file mode 100644 index 37409ec6..00000000 --- a/01 knapsack/01 knapsack recursion memoization table.py +++ /dev/null @@ -1,24 +0,0 @@ -def knapsack(W, wt, val, n, memo): - if memo[n][W] != -1: - return memo[n][W] - - if n == 0 or W == 0: - return 0 - - if wt[n - 1] <= W: - temp = max(val[n - 1] + knapsack(W - wt[n - 1], wt, val, n - 1, memo), - knapsack(W, wt, val, n - 1, memo)) - memo[n][W] = temp - return temp - - else: - temp = knapsack(W, wt, val, n - 1, memo) - memo[n][W] = temp - return temp - -n = 3 -W = 4 -wt = [4, 5, 1] -val = [1, 2, 3] -memo = [[-1 for x in range(W + 1)] for y in range(n + 1)] -print(knapsack(W, wt, val, n, memo)) \ No newline at end of file diff --git a/01 knapsack/01 knapsack recursion.py b/01 knapsack/01 knapsack recursion.py deleted file mode 100644 index edc7fc3a..00000000 --- a/01 knapsack/01 knapsack recursion.py +++ /dev/null @@ -1,16 +0,0 @@ -def knapSack(W, wt, val, n): - if n == 0 or W == 0: - return 0 - - if wt[n - 1] <= W: - return max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), - knapSack(W, wt, val, n - 1)) - - else: - return knapSack(W, wt, val, n - 1) - -n = 3 -W = 4 -wt = [4, 5, 1] -val = [1, 2, 3] -print(knapSack(W, wt, val, n)) \ No newline at end of file diff --git a/CodingClubIndia-master.zip b/CodingClubIndia-master.zip deleted file mode 100644 index 3c4e4966..00000000 Binary files a/CodingClubIndia-master.zip and /dev/null differ