2472: 【普及-】【P1028】数的计算

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:27 解决:18

题目描述

给出自然数 lns="http://www.w3.org/1998/Math/MathML">,要求按如下方式构造数列:

  1. 只有一个数字 lns="http://www.w3.org/1998/Math/MathML"> 的数列是一个合法的数列。
  2. 在一个合法的数列的末尾加入一个大于0的自然数,但是这个自然数不能超过该数列最后一项的一半,可以得到一个新的合法数列。

请你求出,一共有多少个合法的数列。两个合法数列 lns="http://www.w3.org/1998/Math/MathML">, 不同当且仅当两数列长度不同或存在一个正整数 lns="http://www.w3.org/1998/Math/MathML">,使得 lns="http://www.w3.org/1998/Math/MathML">

输入

输入只有一行一个整数,表示 lns="http://www.w3.org/1998/Math/MathML">

输出

输出一行一个整数,表示合法的数列个数。

样例输入 复制

6

样例输出 复制

6

提示

样例 1 解释

满足条件的数列为:

  • lns="http://www.w3.org/1998/Math/MathML">6
  • lns="http://www.w3.org/1998/Math/MathML">6,1
  • lns="http://www.w3.org/1998/Math/MathML">6,2
  • lns="http://www.w3.org/1998/Math/MathML">6,3
  • lns="http://www.w3.org/1998/Math/MathML">6,2,1
  • lns="http://www.w3.org/1998/Math/MathML">6,3,1

数据规模与约定

对于全部的测试点,保证 lns="http://www.w3.org/1998/Math/MathML">1103

#include<bits/stdc++.h>
using namespace std;
int sol(int x){
    if(x==1) return 1;
    int ans=1;
    for(int i=1;i<=x/2;i++)
        ans+=sol(i);
	return ans;
}
int n; 
int main(){
    cin>>n;
    cout<<sol(n);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,
f[1010];
int sol(int x) {
    int ans = 1;
    if (f[x] != -1)
        return f[x];
    for (int i=1; i<=x/2; i++)
        ans += sol(i);
    return f[x] = ans;
}
int main() {
    cin >> n;
    memset(f, -1, sizeof(f));
    f[1] = 1;
    cout << sol(n) << endl;
    return 0;
}