Skip to content

Instantly share code, notes, and snippets.

@OtacilioN
Created October 19, 2020 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OtacilioN/c6a2ed2a214f6a7883be64ca874a281a to your computer and use it in GitHub Desktop.
Save OtacilioN/c6a2ed2a214f6a7883be64ca874a281a to your computer and use it in GitHub Desktop.
Problema 790 do The Huxley https://www.thehuxley.com/problem/790
# 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