http://noi.openjudge.cn/ch0202/3089/
可以看成是从{1,2}中选可重复子序列,使得子序列和为N
DFS枚举问题三段式:
出口if
越界if
枚举递归(通常要for一下)
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
int ans=0;
void dfs(int n)
{
if(n==0)
{
ans++;
return ;
}
if(n<=0) return;
dfs(n-1);
dfs(n-2);
}
int main()
{
//freopen("input.txt","r",stdin);
int n;
while(cin>>n)
{
ans=0;
dfs(n);
cout<<ans<<endl;
}
return 0;
}