Pagini recente » Cod sursa (job #1361204) | Cod sursa (job #1157832) | Cod sursa (job #2877888) | Cod sursa (job #861924) | Cod sursa (job #2662918)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,maxw,dp[10005];
struct obiect
{
int weight,profit;
}wp;
int main()
{
fin>>n>>maxw;
for(int i=1;i<=n;i++)
{
fin>>wp.weight>>wp.profit;
for(int j=maxw;j>=wp.weight;j--)
dp[j]=max((dp[j-wp.weight]+wp.profit),dp[j]);
}
fout<<dp[maxw];
return 0;
}