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

请救啊,,怎么还是WA啊?

Posted by Essence_me at 2005-08-08 10:36:37 on Problem 2184
In Reply To:请问动态规划是这样写的吗? Posted by:Essence_me at 2005-08-08 10:19:51
> #include <stdio.h>
> #include <memory.h>
> 
> #define MAX 200001
> long f[200001];
> int real[200001];
> int main()
> {
> 	long n,max,i,j,si,fi;
> 	scanf("%ld",&n);
> 	for(i=0;i<=200000;i++)f[i]=MAX;				
> 	f[100000]=0;
> 	for(i=0;i<n;i++)
> 	{
> 		scanf("%ld%ld",&si,&fi);
> 		for(j=0;j<=200000;j++)real[j]=1;
> 		for(j=0;j<=200000;j++)
> 		{
> 			if(j+si>=0&&j+si<=200000)
>    			if(f[j]!=MAX&&real[j]&&((f[j]+fi>f[j+si]&&f[j+si]!=MAX)||f[j+si]==MAX))
>       			{
>       				f[j+si]=f[j]+fi;
>      				real[j+si]=0;
>       			}     			
> 		}
> 	}
> 	max=0;
> 	for(i=100000;i<=200000;i++)
> 	{
> 		if(f[i]>=0)
>   		if(f[i]!=MAX&&f[i]+i-100000>max)max=f[i]+i-100000;	
> 	}
> 	printf("%ld\n",max);
> 	
> }

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