Cod sursa(job #2229655)
| Utilizator | Data | 7 august 2018 19:01:26 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
#include<algorithm>
using namespace std;
int dinamic[10001];
int main() {
ifstream inputfile("rucsac.in");
ofstream outputfile("rucsac.out");
int n, maxWeight;
inputfile >> n >> maxWeight;
for(int i = 1; i <= n; i++)
{
int objectWeight, objectValue;
inputfile >> objectWeight >> objectValue;
for(int j = maxWeight - objectWeight; j >= 0 ; j--)
{
dinamic[j + objectWeight] = max(dinamic[j + objectWeight], dinamic[j] + objectValue);
}
}
outputfile << dinamic[maxWeight];
return 0;
}