Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active April 18, 2026 09:08
Show Gist options
  • Select an option

  • Save thinkphp/cb77914cb010279008f42583a6fbfda5 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/cb77914cb010279008f42583a6fbfda5 to your computer and use it in GitHub Desktop.
input pentru problema rucsacului
input:
numar de obiecte, capacitate rucsac
urmatoarele linii:
greutate obiecte, profit obiect
5 10
3 2
4 3
3 8
10 12
5 7
Output: Matricea costurilor, profitul si obiectele alese
Tabel Castig (DP):
0 1 2 3 4 5 6 7 8 9 10
i=0 0 0 0 0 0 0 0 0 0 0 0
i=1 0 0 0 2 2 2 2 2 2 2 2
i=2 0 0 0 2 3 3 3 5 5 5 5
i=3 0 0 0 8 8 8 10 11 11 11 13
i=4 0 0 0 8 8 8 10 11 11 11 13
i=5 0 0 0 8 8 8 10 11 15 15 15
Profit maxim: 15
Obiecte alese: 3 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment