Cod sursa(job #2500281)
Utilizator | Data | 27 noiembrie 2019 17:39:03 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
ifstream i("rucsac.in");
ofstream o("rucsac.out");
int main()
{
int obiecte, gmax,v[10000],greutate,profit;
i >> n >> gmax;
for (int i = 0; i < obiecte; i++)
{
i >> greutate >> profit;
for (int j = gmax; j >= greutate; j--)
if (v[j] = v[j - g] + profit)
v[j] = v[j - g] + profit;
}
o << v[gmax];
}