Created
October 19, 2020 00:38
-
-
Save OtacilioN/c6a2ed2a214f6a7883be64ca874a281a to your computer and use it in GitHub Desktop.
Problema 790 do The Huxley https://www.thehuxley.com/problem/790
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Veja a descrição do problema em https://www.thehuxley.com/problem/790 | |
def mochila(capacidade, lista_pesos, lista_valores, tamanho_lista): | |
matriz_solucao = [[0 for x in range(capacidade + 1)] | |
for x in range(tamanho_lista + 1)] | |
for item in range(tamanho_lista + 1): | |
for peso in range(capacidade + 1): | |
if item == 0 or peso == 0: | |
matriz_solucao[item][peso] = 0 | |
elif lista_pesos[item-1] <= peso: | |
matriz_solucao[item][peso] = max(lista_valores[item-1] + matriz_solucao[item-1] | |
[peso-lista_pesos[item-1]], matriz_solucao[item-1][peso]) | |
else: | |
matriz_solucao[item][peso] = matriz_solucao[item-1][peso] | |
return matriz_solucao[tamanho_lista][capacidade] | |
tamanho_lista, capacidade = map(int, input().split()) | |
lista_valores = [] | |
lista_pesos = [] | |
for item in map(int, input().split()): | |
lista_valores.append(item) | |
for item in map(int, input().split()): | |
lista_pesos.append(item) | |
print(mochila(capacidade, lista_pesos, lista_valores, tamanho_lista)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment