Pagini recente » Cod sursa (job #2463820) | Cod sursa (job #2463987) | Cod sursa (job #3169714) | Cod sursa (job #2442777) | Cod sursa (job #942369)
Cod sursa(job #942369)
#include<cstdio>
#include<cstring>
using namespace std;
int d1[10010],d2[10010];
int main()
{
freopen("rucsac.in","r",stdin);
freopen("rucsac.out","w",stdout);
int i,g,n,p,w,a1,a2;
scanf("%d%d",&n,&g);
while(n)
{
scanf("%d%d",&w,&p);
for(i=1;i<=g;i++)
{
if(w<=i) a1=d1[i-w]+p;
else a1=0;
a2=d1[i];
if(a1>a2) d2[i]=a1;
else d2[i]=a2;
}
memcpy(d1,d2,(g+1)*sizeof(int));
memset(d2,0,sizeof(d2));
n--;
}
printf("%d",d1[g]);
return 0;
}