Cod sursa(job #2733524)
Utilizator | Data | 30 martie 2021 16:19:37 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
std::ifstream f("rucsac.in");
std::ofstream g("rucsac.out");
int res[10003];
int main ()
{
int n, i, j, gmax, greutate, valoare;
f >> n >> gmax;
for (i = 1; i <= n; i += 1)
{
f >> greutate >> valoare;
for (j = gmax; j >= greutate; j -= 1)
res[j] = std::max (res[j], res[j - greutate] + valoare);
}
g << res[gmax];
return 0;
}