Cod sursa(job #2586259)
| Utilizator | Data | 20 martie 2020 11:33:55 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, g;
int sol[10010];
int main() {
fin >> n >> g;
for (int i = 1; i <= n; i++) {
int weight, value;
fin >> weight >> value;
for (int j = g - weight; j >= 0; j--)
sol[j + weight] = max(sol[j + weight], sol[j] + value);
}
fout << sol[g];
return 0;
}
