Pagini recente » Cod sursa (job #63052) | Cod sursa (job #2456091) | Cod sursa (job #1799103) | Cod sursa (job #1754930) | Cod sursa (job #2227780)
#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;
}