mirror of
https://github.com/Code-For-Groningen/temmies.git
synced 2025-07-02 20:04:57 +02:00
Fix bug with multiple file upload. Fixed bug with printing the same TC number. Updated docs to reflect on submit implementation.
This commit is contained in:
28
src/suitcase.py
Normal file
28
src/suitcase.py
Normal file
@ -0,0 +1,28 @@
|
||||
def suitcase(maxVolume, sizes, values, n):
|
||||
|
||||
dp = [[0 for _ in range(maxVolume + 1)] for _ in range(n + 1)]
|
||||
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, maxVolume + 1):
|
||||
if sizes[i - 1] <= j:
|
||||
dp[i][j] = max(values[i - 1] + dp[i - 1][j - sizes[i - 1]], dp[i - 1][j])
|
||||
else:
|
||||
dp[i][j] = dp[i - 1][j]
|
||||
|
||||
return dp[n][maxVolume]
|
||||
|
||||
def main():
|
||||
n, maxVolume = map(int, input().split())
|
||||
sizes = []
|
||||
values = []
|
||||
|
||||
for _ in range(n):
|
||||
item, size, value = input().split()
|
||||
sizes.append(int(size))
|
||||
values.append(int(value))
|
||||
|
||||
maxSatisfaction = suitcase(maxVolume, sizes, values, n)
|
||||
print(maxSatisfaction)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user