0
点赞
收藏
分享

微信扫一扫

nefu 半数集 560 (递归)


半数集

description


给定一个自然数n,由n开始依次产生半数集set(n).set(n)的定义如下:
(1)	n是set(n)中的元素
(2)	在n的左边添加一个自然数,但该自然数不能超过最近添加的数的一半
(3)	按此规律添加,知道不能添加自然数为止。
例如:set(6)={6,16,26,126,36,136}


input


输入有多组,每组输入一个正整数n(0 <  n ≤ 1000)。


output


每组测试实例,输出该半数集的元素个数。


sample_input


1
6


sample_output


1
6


hint



source

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[10010];
int helf(int n)
{
	int ans=1;
	if(a[n])
		return a[n];
	for(int i=1;i<=n/2;i++)
		ans+=helf(i);
	a[n]=ans;
	return ans;
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		memset(a,0,sizeof(a));
		a[1]=1;
		printf("%d\n",helf(n));
	}
	return 0;
	
}

 

Problem : 560

Time Limit : 1000ms

Memory Limit : 65536K

举报

相关推荐

0 条评论