母牛的故事

 

#include <cstdio>

int f(int n)
{
	if(n == 0 || n == 1)	return 1;
	if(n == 2)  return 2;
	
	return f(n - 1) + f(n - 3);
}

int main()
{
	int n;
	while(scanf("%d", &n) && n != 0)
	{
		printf("%d\n", f(n));
	}
	
	return 0;
}

 

#include <cstdio>

int memo[60];

int f(int n)
{
	memo[0] = memo[1] = 1;
	memo[2] = 2;
	
	for(int i = 3; i <= n; ++ i)
	{
		memo[i] = memo[i - 1] + memo[i - 3];
	}
	
	return memo[n];
}

int main()
{
	int n;
	while(scanf("%d", &n) && n != 0)
	{
		printf("%d\n", f(n));
	}
	
	return 0;
}

  

 

 

posted @ 2019-07-29 11:09  青衫客36  阅读(110)  评论(0编辑  收藏  举报