Pagini recente » Cod sursa (job #637408) | Cod sursa (job #612822) | Cod sursa (job #1210626) | Cod sursa (job #2949022) | Cod sursa (job #3277426)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
const int GMAX = 10001, NMAX = 5000;
struct object
{
int weight, profit;
};
int maxProfit[GMAX];
int main()
{
int n, ans = 0, wMax;
f>>n>>wMax;
for(int i=1; i<=n;i++)
{
object obj;
f>>obj.weight>>obj.profit;
for(int w = wMax; w >= obj.weight; w--)
{
maxProfit[w] = max(maxProfit[w], maxProfit[w - obj.weight] + obj.profit);
ans = max(ans, maxProfit[w]);
}
}
g<<ans;
}