| ||||||||||
| 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 | |||||||||
2479 java写的不知道为啥一直runtime error 本地能过,不知道是不是Scanner的原因import java.util.Scanner;
import java.lang.Math;
public class Main{
private static int[] A;
private static int N;
public static int count(int l, int h){
int sum = 0;
for (int i = l; i <= h; i++)
sum += A[i];
return sum;
}
public static int findmax(int l, int h){
int max = Integer.MIN_VALUE;
for(int i = l; i <= h; i++)
for (int j = i; j <= h; j++){
int temp = count(i, j);
if (temp > max)
max = temp;
}
return max;
}
public static int findmax(){
int max = Integer.MIN_VALUE;
int temp;
for (int i = 1; i < N; i++){
temp = findmax(0,i-1) + findmax(i, N-1);
max = Math.max(temp, max);
}
return max;
}
public static void main(String[] args){
int order;
Scanner in = new Scanner(System.in);
while(true){
if (!in.hasNext())
break;
order = in.nextInt();
N = in.nextInt();
A = new int[N];
for (int i = 0; i < N; i++){
A[i] = in.nextInt();
}
System.out.println(findmax());
}
in.close();
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator