Pagini recente » Diferente pentru problema/rege2 intre reviziile 8 si 3 | Diferente pentru problema/rege2 intre reviziile 3 si 4 | Profil radu_luca18 | Monitorul de evaluare | Cod sursa (job #3358691)
#include <bits/stdc++.h>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int profit[501][10001], greut[501], pro[501];
int main()
{
int n, g, maxim = 0, i, j;
in >> n >> g;
for(i = 1; i <= n; i++)
in >> greut[i] >> pro[i];
for(i = 1; i <= n; i++) {
for(j = 1; j <= g; j++) {
profit[i][j] = profit[i - 1][j];
if(j >= greut[i])
profit[i][j] = max(profit[i][j], profit[i - 1][j - greut[i]] + pro[i]);
if(i == n)
maxim = max(maxim, profit[i][j]);
}
}
out << maxim;
return 0;
}