Cod sursa(job #2279882)
Utilizator | Data | 10 noiembrie 2018 10:07:03 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int dp[10005];
int n, g;
int main() {
fin >> n >> g;
for (int i = 1; i <= n; i++) {
int w, p;
fin >> w >> p;
for (int j = g; j >= w; j--) {
int potential = p + dp[j - w];
if (potential > dp[j])
dp[j] = potential;
}
}
fout << dp[g];
return 0;
}