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

我,AC了,贴代码

Posted by yzhw at 2009-09-22 20:34:35 on Problem 2479
In Reply To:有谁用java做的? Posted by:It_is_rainning_now at 2009-08-01 21:01:21
Source Code

Problem: 2479  User: yzhw 
Memory: 3380K  Time: 860MS 
Language: Java  Result: Accepted 

Source Code 
import java.io.*;
public class Main {

	/**
	 * @param args
	 */
		static int data[]=new int[50005];
		static long dp[]=new long[50005];
		static int num;
	public static void main(String[] args) throws IOException{
		StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		int testcase;
		in.nextToken();
		testcase=(int)in.nval;
		dp[0]=0;
		while(testcase--!=0)
		{
			in.nextToken();
			num=(int)in.nval;
			for(int i=1;i<=num;i++)
			{
				in.nextToken();
				data[i]=(int)in.nval;
			}
			long now=0,max=-Long.MAX_VALUE;
			for(int i=1;i<=num;i++)
			{
				if(now+data[i]>data[i]) now=now+data[i];
				else
				{
				  now=data[i];
				}
				if(now>max)
				{
					max=now;		
				}
				dp[i]=max;
				
			}
			now=0;
			max=-Long.MAX_VALUE;
			long total=-Long.MAX_VALUE;
			for(int i=num;i>1;i--)
			{
				if(now+data[i]>data[i]) now=now+data[i];
				else
				{
				  now=data[i];
				}
				if(now>max)
				{
					max=now;		
				}
				total=Math.max(total,dp[i-1]+max);
			}
	
			System.out.println(total);
			
		}

	}

}


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