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

求解,求回答

Posted by 954688947 at 2015-10-27 20:24:24 on Problem 2184
为什么zero要10000才行?1005为什么不行?


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
const int max_a=105;
const int max_b=200100;
const int zero=10050;
int dp[max_b];

int main()
{
    int ans,i,j;
    int t;
    int a[max_a],b[max_b];
    while(~scanf("%d",&t))
    {
        for(i=1;i<=t;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
        }
        memset(dp,-inf,sizeof(dp));
        dp[zero]=0;
        for(i=t;i>0;i--)
        {
            if(a[i]>0)
            {
                for(j=max_b-1;j>=a[i];j--)
                    dp[j]=max(dp[j-a[i]]+b[i],dp[j]);

            }
            else
            {
                for(j=0;j<max_b+a[i];j++)
                    dp[j]=max(dp[j-a[i]]+b[i],dp[j]);
            }
        }
        ans=0;
        for(i=zero;i<max_b;i++)
        {
            if(dp[i]>0 && (i-zero+dp[i]>ans))
                ans=i-zero+dp[i];
        }
        printf("%d\n",ans);
    }


    return 0;
}




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