Pagini recente » Cod sursa (job #326806) | Cod sursa (job #931299) | Cod sursa (job #440437) | Cod sursa (job #2513796) | Cod sursa (job #3278984)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, Gmax, greutate[1001]{}, profit[1001]{}, dp[1001][10001]{}, x;
int main(){
fin >> n >> Gmax;
for(int i = 1; i <= n; i++)
fin >> greutate[i] >> profit[i];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= Gmax; j++){
if(greutate[i] > j)
dp[i][j] = dp[i-1][j];
else
dp[i][j] = max(dp[i-1][j], dp[i-1][j-greutate[i]] + profit[i]);
}
}
fout << dp[n][Gmax];
}