Pagini recente » Cod sursa (job #17488) | Cod sursa (job #2079924) | Cod sursa (job #1403624) | Cod sursa (job #453408) | Cod sursa (job #2491009)
#include<bits/stdc++.h>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int weight[5000],profit[5000];
int n,max_weight;
int dp[10001][5001];
void read()
{
in>>n>>max_weight;
for(int i=0; i<n; i++)
{
in>>weight[i]>>profit[i];
}
}
int knapsack()
{
for(int i=1; i<=n; i++)
{
for(int g=0; g<=max_weight; g++)
{
if(weight[i-1]<=g)
{
dp[i][g]=max(dp[i-1][g],dp[i-1][g-weight[i-1]]+profit[i-1]);
}
}
}
return dp[n][max_weight];
}
int main()
{
read();
out<<knapsack();
}