Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

磨蹭了N天,终于、、、、终于搞定了一个背包,哈哈哈、、、、代码

Posted by D_e_n_g at 2012-08-07 13:55:15 on Problem 3624
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator