Pagini recente » Borderou de evaluare (job #3110277) | Monitorul de evaluare | Cod sursa (job #3310504) | Cod sursa (job #3330712) | Cod sursa (job #3344208)
#include <bits/stdc++.h>
int weight[5001];
int profit[5001];
std::ifstream fin("rucsac.in");
std::ofstream fout("rucsac.out");
int dp[10001];
int main()
{
int n, G;
fin >> n >> G;
for(int i = 1; i <= n; i++)
{
fin >> weight[i] >> profit[i];
}
for(int i = 1; i <= n; i++)
{
for(int g = G; g >= 1; g--)
{
if(g >= weight[i])
{
dp[g] = std::max(dp[g], dp[g - weight[i]] + profit[i]);
}
}
}
fout << dp[G];
}