Cod sursa(job #891001)
Utilizator | Data | 25 februarie 2013 13:07:20 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.32 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int V[50000];
int N,G;
int x,y;
int main()
{
f >> N >> G;
for(int i = 1; i <= N; i++) {
f >> x >> y;
for(int j = G; j >= x; j--) {
V[j] = max(V[j], V[j-x] + y);
}
}
g << V[G];
}