Pagini recente » Diferente pentru dinic intre reviziile 19 si 18 | Cod sursa (job #1520332) | Monitorul de evaluare | Diferente pentru problema/jb intre reviziile 17 si 16 | Cod sursa (job #2721128)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int DP[2][10005];
int n,G;
int main()
{
int i,j,W,P,l=1;
fin>>n>>G;
for(i = 1; i <= n; i++){
fin>>W>>P;
for(j = 1; j < W; j++){
DP[l][j] = max(DP[1-l][j],DP[l][j-1]);
}
for(j = W; j <= G; j++){
DP[l][j] = max( max( DP[1-l][j], DP[1-l][j-W]+P ) , DP[l][j-1]);
}
l = 1-l;
}
fout<<DP[1-l][G]<<'\n';
return 0;
}