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

WA?

Posted by hheq121 at 2008-08-18 20:58:15 on Problem 2593
#include<iostream>
using namespace std;
int maxsum(int m,int n,int *a);
int main()
{
	int n;int i;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		int *p;
		p=new int [n+5];
		for(i=0;i<n+5;i++)
			p[i]=0;
		for(i=;i<=n;i++)
			scanf("%d",&p[i]);
		printf("%d\n",maxsum(2,n,p));
		delete[]p;
	}
	return 0;
}
int maxsum(int m,int n,int *a)
{
	int i,j;
	if(n<m||m<1)
		return 0;
	int *b=new int [n+1];
	int *c=new int [n+1];
	b[0]=0;c[1]=0;
	for(i=1;i<=m;i++)
	{
		b[i]=b[i-1]+a[i];
		c[i-1]=b[i];
		int max=b[i];
		for(j=i+1;j<=i+n-m;j++)
		{
			b[j]=b[j-1]>c[j-1]?b[j-1]+a[j]:c[j-1]+a[j];
			c[j-1]=max;
			if(max<b[j])
				max=b[j];

		}
		c[i+n-m]=max;
	}
	int sum=0;
	for(j=m;j<=n;j++)
		if(sum<b[j])
			sum=b[j];
		return sum;
}

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