Cod sursa(job #2143000)
| Utilizator | Data | 25 februarie 2018 14:21:41 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int Mem[3][10005],linie,coloana;
int n,G,auxG,auxV;
int main()
{
fin>>n>>G;
for (linie=1;linie<=n;linie++)
{
fin>>auxG>>auxV;
for (coloana=1;coloana<=G;coloana++)
{
Mem[2][coloana]=Mem[1][coloana];
if (auxG<=coloana)
Mem[2][coloana]=max(Mem[1][coloana],Mem[1][coloana-auxG]+auxV);
}
for (coloana=1;coloana<=G;coloana++)
Mem[1][coloana]=Mem[2][coloana];
}
fout<<Mem[2][G];
return 0;
}
