poj2593 Max Sequence

和poj2479同一类型
#include <stdio.h>
#include <string.h>
#define num 100005
int main()
{
	int n,i,sum,maxsum;
	int a[num],arr_1[num],arr_2[num];
	while(scanf("%d",&n)!=EOF&&n)
	{
		memset(a,0,sizeof(a));
		memset(arr_1,0,sizeof(arr_1));
		memset(arr_2,0,sizeof(arr_2));
		sum=0,maxsum=-1005;
		for(i=0;i<n;i++)
		{
		    scanf("%d",&a[i]);
		    sum+=a[i];
		    if(sum>maxsum)
		        maxsum=sum;
		    if(sum<0)
			sum=0;
		    arr_1[i]=maxsum;
	    }
	    sum=0,maxsum=-1005;
	    for(i=n-1;i>=0;i--)
	    {
	    	sum+=a[i];
	    	if(sum>maxsum)
	    	    maxsum=sum;
	    	if(sum<0)
	    	    sum=0;
	    	arr_2[i]=maxsum;
	    }
	    maxsum=-1005;
	    for(i=0;i<n-1;i++)
	    if(arr_1[i]+arr_2[i+1]>maxsum)
	        maxsum=arr_1[i]+arr_2[i+1];
	    printf("%d\n",maxsum);
	}
	return 0;
}

你可能感兴趣的:(sequence,sequence,max,poj2593Max,poj2593,poj2479)