Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

感觉挺容易懂的,,,仅供参考....

Posted by yy17yy at 2010-11-10 14:48:08 on Problem 2479
#include <iostream>
using namespace std;
#define max(a,b) ((a>b)?(a):(b))
int a[50001];//数据数组
int dpy[50001];//前i个数的1个子串的最大值,,必包含第i个..
int dpn[50001];//前i个数的1个子串的最大值,,不必包含第i个..
int dp2[50001];//前i个数的2个子串的最大值,必包含第i个...
int main()
{
	int t;
	for(scanf("%d",&t);t--;)
	{
		int n;
		scanf("%d",&n);
		int i;
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		dpy[0]=dpn[0]=-1000000;
		for(i=1;i<=n;i++)
		{
			dpy[i]=max(dpy[i-1]+a[i],a[i]);
			dpn[i]=max(dpy[i],dpn[i-1]);
		}
		int ans=INT_MIN;
		dp2[1]=a[1];
		for(i=2;i<=n;i++)
		{
			dp2[i]=max(dpn[i-1]+a[i],dp2[i-1]+a[i]);
			ans=max(dp2[i],ans);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator