Skip to content

Commit

Permalink
Added W05 materials
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSol committed Nov 1, 2023
1 parent cba90dc commit c2fed55
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[ContestID_W02]: https://contest.yandex.ru/contest/54016/?lang=en
[ContestID_W03]: https://contest.yandex.ru/contest/54346/?lang=en
[ContestID_W04]: https://contest.yandex.ru/contest/54765/?lang=en
[ContestID_W05]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W05]: https://contest.yandex.ru/contest/55196/?lang=en
[ContestID_W06]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W07]: https://contest.yandex.ru/contest/<CID>/?lang=en
[ContestID_W08]: https://contest.yandex.ru/contest/<CID>/?lang=en
Expand All @@ -17,7 +17,7 @@
[WarmUp_test_W02]: https://forms.gle/xdDXeFT1DCcB5myn7
[WarmUp_test_W03]: https://forms.gle/MrCR6BrWwGsKjqYx7
[WarmUp_test_W04]: https://forms.gle/Bp8e6XhezbHsiVWC8
[WarmUp_test_W05]: https://forms.gle/<form_id>
[WarmUp_test_W05]: https://forms.gle/dWe6UWg4jmEAzt6v7
[WarmUp_test_W06]: https://forms.gle/<form_id>
[WarmUp_test_W07]: https://forms.gle/<form_id>
[WarmUp_test_W08]: https://forms.gle/<form_id>
Expand All @@ -43,13 +43,13 @@
| 02 | Binary search | [Slides][Slides_W02] | [Test][WarmUp_test_W02] | [Contest][ContestID_W02] | 18.10.2023 19:00 UTC+3 |
| 03 | Basic Data sturctures | [Slides][Slides_W03] | [Test][WarmUp_test_W03] | [Contest][ContestID_W03] | 25.10.2023 19:00 UTC+3 |
| 04 | Dynamic programming | [Slides][Slides_W04] | [Test][WarmUp_test_W04] | [Contest][ContestID_W04] | 01.11.2023 19:00 UTC+3 |
| 05 | Knapsack problem | [Slides][Slides_W05] | [Test][WarmUp_test_W05] | [Contest][ContestID_W05] | 13.11.2023 19:00 UTC+3 |
<!---
| 05 | Knapsack problem | [Slides][Slides_W05] | [Test][WarmUp_test_W05] | [Contest][ContestID_W05] | ??.11.2023 19:00 UTC+3 |
| 06 | KMP & Heap | [Slides][Slides_W06] | [Test][WarmUp_test_W06] | [Contest][ContestID_W06] | ??.11.2023 19:00 UTC+3 |
| 07 | DFS & BFS | [Slides][Slides_W07] | [Test][WarmUp_test_W07] | [Contest][ContestID_W07] | ??.12.2023 19:00 UTC+3 |
| 08 | Shortest paths | [Slides][Slides_W08] | [Test][WarmUp_test_W08] | [Contest][ContestID_W08] | ??.12.2023 19:00 UTC+3 |
| 09 | RSQ & RMQ | [Slides][Slides_W09] | [Test][WarmUp_test_W09] | [Contest][ContestID_W09] | ??.12.2023 19:00 UTC+3 |
| 10 | Hashing | [Slides][Slides_W10] | [Test][WarmUp_test_W10] | [Contest][ContestID_W10] | ??.12.2023 19:00 UTC+3 |
| 06 | KMP & Heap | [Slides][Slides_W06] | [Test][WarmUp_test_W06] | [Contest][ContestID_W06] | 20.11.2023 19:00 UTC+3 |
| 07 | DFS & BFS | [Slides][Slides_W07] | [Test][WarmUp_test_W07] | [Contest][ContestID_W07] | 27.11.2023 19:00 UTC+3 |
| 08 | Shortest paths | [Slides][Slides_W08] | [Test][WarmUp_test_W08] | [Contest][ContestID_W08] | 04.12.2023 19:00 UTC+3 |
| 09 | RSQ & RMQ | [Slides][Slides_W09] | [Test][WarmUp_test_W09] | [Contest][ContestID_W09] | 11.12.2023 19:00 UTC+3 |
| 10 | Hashing | [Slides][Slides_W10] | [Test][WarmUp_test_W10] | [Contest][ContestID_W10] | 18.12.2023 19:00 UTC+3 |
| 11 | Binary Search Tree | [Slides][Slides_W11] | None | None | None |
--->

Expand Down
Binary file added week05_knapsack/MSAI.2023.Algo.W05.slides.pdf
Binary file not shown.
47 changes: 47 additions & 0 deletions week05_knapsack/knapsack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
W = 8
N = 4
wi = [3, 3, 5, 6]
ci = [3, 5, 10, 14]

d = [[0] * (W + 1) for i in range(N + 1)]
for i in range(1, N + 1):
for w in range(1, W + 1):
if wi[i-1] > w:
d[i][w] = d[i-1][w]
else:
d[i][w] = max(d[i-1][w], d[i-1][w-wi[i-1]]+ci[i-1])

print('\n'.join([' '.join(map(str, d[i])) for i in range(N + 1)]))


# Python3 program to find maximum
# achievable value with a knapsack
# of weight W and multiple instances allowed.

# Returns the maximum value
# with knapsack of W capacity
def unboundedKnapsack(W, n, val, wt):
# dp[i] is going to store maximum
# value with knapsack capacity i.
dp = [0 for i in range(W + 1)]

ans = 0

# Fill dp[] using above recursive formula
for i in range(W + 1):
for j in range(n):
if (wt[j] <= i):
dp[i] = max(dp[i], dp[i - wt[j]] + val[j])
print(dp)
return dp[W]


# Driver program
W = 5
val = [10]
wt = [2]
n = len(val)

print(unboundedKnapsack(W, n, val, wt))

# This code is contributed by Anant Agarwal.

0 comments on commit c2fed55

Please sign in to comment.