Pagini recente » Cod sursa (job #428712) | Cod sursa (job #2708549) | Cod sursa (job #1742819) | Cod sursa (job #312649) | Cod sursa (job #2652337)
#include<fstream>
#include<iostream>
#include <algorithm>
using namespace std;
ifstream f ("rucsac.in");
ofstream g("rucsac.out");
long long n,gmax,rasp;
long long matr[5001][10001];
int main()
{
f >> n >> gmax;
for(int i = 1;i<=n;i++)
{
long long gr,cost;
f >> gr>> cost;
for(int j = 1;j<=gmax;j++)
{
if(j-gr>=1)
matr[i][j] = max(matr[i-1][j],matr[i-1][j-gr]+cost);
else
matr[i][j] = matr[i-1][j];
}
}
g << matr[n][gmax];
}