解题思路:双递归,构建一个类似二叉树的结构,左子树+1,右子树+2
注意事项:
参考代码:
#include <iostream>
#include <deque>
#include <string>
#include <iterator>
#include <vector>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string.h>
using namespace std;
int ans;
int n;
void dfs(int a)
{
if(a>n)
return ;
if(a==n)
{
ans++;
return ;
}
dfs(a+1);
dfs(a+2);
}
int main()
{
cin>>n;
dfs(0);
cout<<ans<<endl;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:722 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:687 |
printf基础练习2 (C语言代码)浏览:591 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:735 |
C语言训练-素数问题 (C语言代码)浏览:1654 |
wu-淘淘的名单 (C++代码)浏览:1337 |
水仙花 (C语言代码)浏览:1047 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:556 |
出圈】指针malloc版浏览:355 |
1048题解(读入回车问题)浏览:554 |