Cod sursa(job #2978236)
| Utilizator | Data | 13 februarie 2023 15:31:55 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");
int m[5001][10001];
int Gmax,g,v,auxv;
short n;
int main()
{
fin>>n>>Gmax;
for (int i=1;i<=n;i++)
{
fin>>g>>v;
g++;
v++;
for (int j=g;j<=Gmax;j++)
{
auxv=v+m[i-1][j-g];
if (auxv>m[i-1][j])
m[i][j]=auxv;
else m[i][j]=m[i-1][j];
}
for (int j=1;j<g;j++)
m[i][j]=m[i-1][j];
}
fout<<m[n][Gmax]-1;
return 0;
}
