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

Re:高手看下我写的2229有何问题啊!!

Posted by nenu10_wangd at 2010-07-22 16:49:22 on Problem 2229
In Reply To:高手看下我写的2229有何问题啊!! Posted by:920322696 at 2010-03-20 20:06:46
> #include"stdio.h"
> long f(int n){
> 	if(n==1)return 1;
> 	if(n==2)return 2;
> 	if(n%2!=0)return f(n-1);
> 	if(n%2==0){ 
> 		f(n)=f(n-2)+f(n/2);
> 		return f(n);
> 	}
> }
> 	void main(){
> 		int n;
> 		scanf("%d",&n);
> 		printf("%d",f(n));
> 	}





这样写是要超时的,我是开个数组用DP写的。
另:输出没有换行。

> 		f(n)=f(n-2)+f(n/2);
> 		return f(n);

f(n)好像不能作为左值,可以将上两行写成这样return f(n-2)+f(n/2);

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