Cod sursa(job #1644095)
Utilizator | Data | 9 martie 2016 21:31:29 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int i, j, x, y, n, w, c[10005], max1;
int main()
{
f >> n >> w;
for (;n;n--)
{
f >> x >> y;
for (i = w; i >= x; i--)
c[i] = max(c[i-x]+y, c[i]);
}
for (i = 1; i <= w; i++)
max1 = max(c[i], max1);
g << max1;
return 0;
}