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 1120101780 at 2011-07-06 16:24:14 on Problem 1953
#include<stdio.h>
int fa(int n)
{
	int m;
	if(n==1)
		m=2;
	else
		if(n==2)
			m=3;
		else  m=fa(n-1)+fa(n-2);
		return(m);
}
			
void main()
{
	int i,j,m,n,p;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		p=fa(m);
		printf("Scenario #%d:\n%d\n",i+1,p);
	}
}

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