HDOJ1003

来源:互联网 发布:阿里云 流量充值 api 编辑:程序博客网 时间:2024/05/24 06:39


 #include<stdio.h>

#include<stdlib.h>

#include<math.h>

#include<iostream>

#include<string.h>
#define inf 0x3f3f3f
using namespace std;

int a[10000],m[10000],dp[10000];

int main()
{
    int test,n,maxx,x;
    while(scanf("%d",&test) != EOF)
    {
        for(int i = 1 ; i <= test ; i++)
        {
            scanf("%d",&n);
            for(int j = 1 ; j <= n ; j++)
                scanf("%d",&a[j]);
            m[0]= 1;
            dp[0] = 0;
            for(int j = 1 ; j <= n ; j++)
            {
                if(dp[j-1] >= 0)
                {
                    dp[j] = dp[j-1] + a[j];
                    m[j] = m[j-1];
                }
                else
                {
                    dp[j] = a[j];
                    m[j] = j;
                }
            }
            maxx = -inf;
            for(int j = 1 ; j <= n ; j++)
            {
                if(maxx < dp[j])
                {
                    maxx = dp[j];
                    x = j;
                }
            }
            printf("Case %d:\n%d %d %d\n",i,maxx,m[x],x);
            if(i != test)printf("\n");
        }
    }
}

这个题目一开始就打对了。不过一直是WA,后来才知道是因为把数组开在里面了.也不知道为什么,如果开在外面的话会是RTE,所以以后要长记性,再小的数组也不要再开在里面了.