Cod sursa(job #1652049)
Utilizator | Data | 14 martie 2016 16:13:52 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int mat[10003];
int main() {
int n,g;
in >> n >> g;
int Gi,Vi;
for(int i = 1; i <= n; i++) {
in >> Gi >> Vi;
for(int j = g; j >= Gi; j--)
if(mat[j-Gi]+Vi > mat[j])
mat[j] = mat[j-Gi]+Vi;
}
out << mat[g];
return 0;
}