Pagini recente » Cod sursa (job #2641946) | Cod sursa (job #1092805) | Cod sursa (job #671844) | Cod sursa (job #1289944) | Cod sursa (job #2471745)
#include<bits/stdc++.h>
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
int elemente,profit[1001],cost[1001];
int capacitate;
void read()
{
in>>elemente>>capacitate;
for(int i=0; i<elemente; i++)
{
in>>profit[i]>>cost[i];
}
}
int dp[1002][5002];
int knapsack(int index,int cap)
{
if(index==-1 && cap>0)
{
return 99999999;
}
if(cap<=0)
{
return 0;
}
else
{
int a=knapsack(index-1,cap);
int b=cost[index]+knapsack(index-1,cap-profit[index]);
return min(a,b);
}
}
int main()
{
read();
out<<knapsack(elemente-1,capacitate);
}