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 swordl3 at 2012-07-05 10:14:48 on Problem 1163
#include <stdio.h>

int max;

void add(int a[1000],int n,int left,int right,int now,int num)//now为当前要加的层
{   
	if(now==n+1)
	{
		if(max<num)
		{
			max=num;
		}
		return ;
	}
	else 
	{
		add(a,n,left+now,right+now,now+1,num+a[left]);
		add(a,n,left+now+1,right+now+1,now+1,num+a[right]);
	}
}
int main()
{
	int n,i,n1,num;
	int a[1000];
	scanf("%d",&n);
	n1=n*(n+1)/2;
	for(i=0;i<n1;i++)
	{
		scanf("%d",&a[i]);
	}
	max=0;
	num=0;
	add(a,n,1,2,2,a[0]);
	printf("%d\n",max);
	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