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 dexter at 2004-02-22 17:50:57 on Problem 1163
#include<stdio.h>
int a[100][100];//下三角形存放数据
int max1(int i,int j,int n)//递归函数
{
	int left,right;
	if((i==n-1)||(j==n-1))//到达边缘
		return a[i][j];
	left=max1(i+1,j,n);//左边
	right=max1(i+1,j+1,n);//右边
	return (left>right)? (left+a[i][j]):(right+a[i][j]);
}
main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<=i;j++)
			scanf("%d",&a[i][j]);
	printf("%d",max1(0,0,n));
}

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