Cod sursa(job #1777489)
Utilizator | Data | 12 octombrie 2016 16:07:18 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <cstdio>
#include <algorithm>
using namespace std;
int n, g;
int mat[10010];
int profit[10010];
void citire()
{
scanf("%d %d", &n, &g);
int tmp1, tmp2;
for(int i = 1; i <= n; i++)
{
scanf("%d %d", &tmp1, &tmp2);
for(int j = g; j >= tmp1; j--)
{
mat[j] = max(mat[j], tmp2 + mat[j - tmp1]);
}
}
printf("%d", mat[g]);
}
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
citire();
return 0;
}