Pagini recente » Cod sursa (job #573215) | Cod sursa (job #2840199) | Cod sursa (job #1711113) | Cod sursa (job #621508) | Cod sursa (job #2635319)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
#define nmax 10005
int best[nmax][nmax], n, p[nmax], w[nmax],wmax;
int main()
{
fin >> n >> wmax;
for (int i = 1; i <= n; i++)
{
in >> w[i] >> p[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= wmax; j++)
{
best[i][j] = best[i - 1][j];
if (w[i]<=j)
best[i][j] = max(best[i - 1][j], best[i - 1][j - w[i]] + p[i]);
}
}
fout << best[n][wmax];
}