Cod sursa(job #2227780)
Utilizator | Data | 1 august 2018 18:35:58 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
int dp[10001];
int main()
{
ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");
int n, maxWeight;
fin >> n >> maxWeight;
for (int i = 1; i <= n; ++i) {
int currentWeight, currentValue;
fin >> currentWeight >> currentValue;
for (int j = maxWeight - currentWeight; j >= 0; --j) {
dp[j + currentWeight] = max (dp[j + currentWeight], dp[j] + currentValue);
}
}
fout << dp[maxWeight];
return 0;
}