例4.6 - 数的计数 - 奇偶1阶递推
程序员文章站
2022-07-16 21:23:08
...
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<typeinfo>
#include<sstream>
#include<fstream>
#include<algorithm>
using namespace std;
int h[101]; //存量思维
int n=0;
void coutN(int n){ //求h[n]
h[1] = 1; //设置递推边界
for(int i=2;i<=n;i++){
if(i%2 == 0){ //偶数时
h[i] = h[i-1] + h[i/2];
} else{
h[i] = h[i-1];
}
}
}
int main()
{
//流程图!!
cout << "输入:";
cin >> n;
coutN(n); //开始计数
cout << "总数:" << h[n];
return 0;
}
//cout << "输入:";