Cod sursa(job #942424)
Utilizator | Data | 22 aprilie 2013 15:05:59 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include<fstream>
#include<cstring>
#include<algorithm>
using namespace std;
int d1[10010],d2[10010];
int main()
{
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,g,p,w,mx=0,pmax=0;
fin>>n>>g;
int i,j;
for(i=1;i<=n;++i)
{
fin>>w>>p;
for(j=1;j<=g;++j)
{
if(j<w)
{
d2[j]=d1[j];
}else
{
d2[j]= max(d1[j],d1[j-w]+p);
}
}
memcpy(d1,d2,sizeof(d2));
}
fout<<d1[g];
return 0;
}