hdu max sum

这题跟求最大连续数列一样的,稍微不同的是只要把值改为标号就可以了。

#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<debug.h>
#define X 100001
int A[X];
int main( )
{
int N,M,a,b,c,d,e,f,x,i,y,sum,len=0;
Debug();
scanf(
"%d",&N);
while(N--)
{
len
++;
memset(A,
0,sizeof(A));
scanf(
"%d",&M);
for(i=0;i<M;i++)
scanf(
"%d",&A[i]);
f
=sum=a=b=A[0];
c
=d=x=y=1;

for(i=1;i<M;i++)
{

if(sum>=0)
sum
+=A[i],c=i+1;
else
sum
=A[i],d=c=i+1;
if(sum>f)
{
f
=sum;
y
=c;
x
=d;
}
}
printf(
"case %d:\n%d %d %d\n",len,f,x,y);
printf(N
?"\n":"");
}
//system("pause");
return 0;
}




posted on 2011-04-19 20:19  more think, more gains  阅读(188)  评论(0编辑  收藏  举报

导航