Cod sursa(job #2672972)
| Utilizator | Data | 15 noiembrie 2020 16:18:29 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
const int nmax=5000;
int a[nmax+5][10006],n,g,profit=0;
int main()
{
int i,x,y,j;
fin>>n>>g;
for(i=1;i<=n;i++)
{
fin>>y>>x;
for(j=1;j<=g;j++)
{
if(j>=y) a[i][j]=max(a[i-1][j],a[i-1][j-y]+x);
else a[i][j]=a[i-1][j];
if(a[i][j]>=profit)
{
profit=a[i][j];
}
}
}
fout<<profit;
return 0;
}
