Pagini recente » Cod sursa (job #2955679) | Cod sursa (job #1264989) | Cod sursa (job #743779) | Cod sursa (job #719426) | Cod sursa (job #3244391)
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct obj
{
int greutate, profit;
};
int main()
{
int dp[10001]={};
obj chestii[5001];
int n,gmax;
fin>>n>>gmax;
for(int i=1;i<=n;i++)
fin>>chestii[i].greutate>>chestii[i].profit;
for(int i=1;i<=n;i++)
{
for(int g=gmax;g>=chestii[i].greutate;g--)
dp[g]=max(dp[g-chestii[i].greutate]+chestii[i].profit,dp[g]);
}
fout<<dp[gmax];
return 0;
}