hdu 1003 Max Sum

//dp,注意转移要领,动手模拟一下

#include<stdio.h>
#define max(a,b) (a>b?a:b)
int main(void)
{

    int
t,n,a[100005];
    int
st,et,po;
    int
max,now;
    int
k=1;
    scanf("%d",&t);
    while
(t--)
    {

        scanf("%d",&n);
        for
(int i=1;i<=n;i++) scanf("%d",&a[i]);
        max=now=a[1];
        st=et=po=1;
        for
(int i=2;i<=n;i++){
            if
(now+a[i]<a[i]){
                now=a[i];
                po=i;
            }
else now+=a[i];
            if
(now>max){
                max=now;
                st=po;
                et=i;
            }
        }

        printf("Case %d:\n%d %d %d\n",k++,max,st,et);
        if
(t) printf("\n");
    }

    return
0;
}

posted @ 2013-09-11 19:18  heaventouch  阅读(78)  评论(0编辑  收藏  举报