日期:2014-05-20  浏览次数:20635 次

杭电acm 1003提交一直是wrong answer!!求大神帮忙,刚接触acm
本帖最后由 chen820655096 于 2013-02-09 00:15:33 编辑
题目要求:
Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
 
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
 
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
 
Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
 
Sample Output
Case 1:
14 1 4

Case 2:
7 1 6
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main{
    public static void main(String []args){
        //下面的这种试读取速度比较快。
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a=0; 
        a=sc.nextInt();//a为输入的样例数
        int reslt[][]=new int[a][2];//存放结果
        int s[][]=new int [a][30];//存放输入的数
        for(int i=0;i<a;i++){
         int b=0,sum=0;
         b=sc.nextInt();
         int sum1[]=new int[b];
         sum=0;
         for(int j=0;j<b;j++){
         s[i][j]=sc.nextInt();
         sum=sum+s[i][j];
         sum1[j]=sum;
         }
         reslt[i][0]=maxsum(sum1);//存放最后的结果
         reslt[i][1]=sum1[0];
        }
        for(int m=0;m<a;m++){
         System.out.println("Case "+(m+1)+":");
         System.out.println(reslt[m][1]+" "+1+" "+(reslt[m][0]+1));