Pagini recente » Cod sursa (job #2638972) | Cod sursa (job #2759882) | Cod sursa (job #2328711) | Cod sursa (job #2305083) | Cod sursa (job #2779003)
#include <fstream>
#include <vector>
using namespace std;
struct obiect
{
int greutate;
int profit;
};
vector <obiect> v;
int dp[10009];
int main()
{
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n;
fin>>n;
int gmax;
fin>>gmax;
for(int i=0;i<n;i++)
{
int g,p;
fin>>g>>p;
obiect nou;
nou.greutate=g;
nou.profit=p;
v.push_back(nou);
}
for(int j=0;j<n;j++)
{
for(int g=gmax;g>=0;g--)
{
if(g-v[j].greutate>=0)
dp[g]=max(dp[g],dp[g-v[j].greutate]+v[j].profit);
}
}
fout<<dp[gmax];
return 0;
}