| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
磨蹭了N天,终于、、、、终于搞定了一个背包,哈哈哈、、、、代码#include<stdio.h>
#include<string.h>
int main()
{
int i,j,m,n;
int w[3403],d[3403],f[13000];
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d %d",&w[i],&d[i]);
}
memset(f,0,13000*sizeof(int));
for(i=1;i<=n;i++)
for(j=m;j>=w[i];j--)
{
f[j]=f[j]>(f[j-w[i]]+d[i])?f[j]:(f[j-w[i]]+d[i]);
}
printf("%d\n",f[m]);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator