Cod sursa(job #2721160)
| Utilizator | Data | 11 martie 2021 16:50:05 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 55 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#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] = DP[1-l][j];
}
for(j = W; j <= G; j++){
DP[l][j] = max( DP[1-l][j], DP[1-l][j-W]+P );
}
l = 1-l;
}
fout<<DP[l][G]<<'\n';
return 0;
}
