Cod sursa(job #1560999)
| Utilizator | Data | 3 ianuarie 2016 16:08:27 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
# include <cstdio>
# include <algorithm>
# define G 10010
using namespace std;
int numar_obiecte, greutate_maxima, greutate, profit;
int sol[G];
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
scanf("%d %d\n", &numar_obiecte, &greutate_maxima);
for(int i=1; i<=numar_obiecte; ++i)
{
scanf("%d %d\n", &greutate, &profit);
for(int j=greutate_maxima; j>=greutate; --j)
sol[j]=max(sol[j],sol[j-greutate]+profit);
}
printf("%d\n", sol[greutate_maxima]);
}
