Cod sursa(job #1718147)
Utilizator | Data | 16 iunie 2016 19:39:14 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream o("rucsac.out");
const int nmx = 10002;
int n,g,v[nmx];
int main()
{
f >> n >> g;
for(int i = 1; i <= n; ++i)
{
int w, val;
f >> w >> val;
for(int j = g; j >= w; --j)
v[j] = max(v[j],v[j-w] + val);
}
o << v[g] << "\n";
return 0;
}