3381 - 数的计算
我们要求找出具有下列性质数的个数(包含输入的自然数n):
先输入一个自然数n(n≤1000),然后对此自然数按照如下方法进行处理
l·不作任何处理:
2·在它的左边加上一个自然数,但该自然数不能超过原数的一半;
3·加上数后,继续按此规则进行处理,直到不能再立生自然数为止。
Input
自然数n
Output
满足条件的数的个数
Examples
Input
6
Output
6
Hint
题目来源:吕红波
Solution C++
//用f(n)表示自然数n所能扩展的数据总个数,则f(1)=1,f(2)=2,f(3)=2,f(4)=4,f(5)=4,f(6)=6,f(7)=6,f(8)=10,f(9)=10。 #include <cstdio> int f[1001]; using namespace std; int main() { int n; int i, j; scanf("%d", &n); for(i = 1; i <= n; i++) { f[i] = 1; for(j = 1; j <= i / 2; j++) f[i] += f[j]; } printf("%u\n", f[n]); return 0; }
Hint
题目来源:吕红波