求区间连续最大和,DP之。
/*
* HDU-1003 max sum
* mike-w
* 2011-8-30
* ----------------
* HINT:DP?
* ----------------
* 最大连续子序列和
* 参见 http://hi.baidu.com/%D1%A9%CE%E8%B1%F9%B7%E2acm/blog/item/0430af0d6c3197e6aa645712.html
*/
#include<stdio.h>
int main(void)
{
long T,N;
long sum,start,end;
long t,tsum,ts;
long i,j;
#ifndef ONLINE_JUDGE
freopen("1003.in","r",stdin);
#endif
scanf("%ld",&T);
for(i=1;i<=T;i++)
{
scanf("%ld",&N);
start=ts=1;
sum=-(1<<30); /* attention here! */
tsum=0;
for(j=1;j<=N;j++)
{
scanf("%ld",&t);
tsum+=t;
if(tsum<t)
tsum=t,ts=j;
if(sum<tsum)
sum=tsum,start=ts,end=j;
}
printf("Case %ld:\n%ld %ld %ld\n",i,sum,start,end);
if(i<T) putchar('\n');
}
return 0;
}