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

此题 数据 应该有问题!!!!!输入 0 的时候,输出必须是1

Posted by pojwjk96 at 2012-07-25 13:54:23 on Problem 2663
抛开此题,输入 0 的时候应该是 0 
但是加了上述条件却WA...

所以大家去掉上面的那个条件就好

送几行 菜鸟 递归代码:

#include <iostream>
using namespace std;

const int Max = 31;
int n;
long data[Max];

long f(int n)
{
	int i;
	long times = 0;
	if(n == 0)
		return 1;
	if(n == 2)
		return 3;

	if(data[n] > 0)
		return data[n];

	times += 3 * f(n - 2);
	for(i = 4;n - i >= 0;i += 2)
	{
		times += 2 * f(n - i);
	}
	data[n] = times;
	return times;
}

int main()
{
	int i;
	for(i = 0;i < Max;i++)
	{
		data[i] = -1;
	}
	while(cin >> n && n >= 0)
	{
		if(n % 2 != 0)
		{
			cout << 0 << endl;
			continue;
		}
		cout << f(n) << endl;
	}
	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