莫名其妙的递归写法hhh,因为前面那些题都是递归,就写了这样。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
ll a[50];
void dfs(int x)
{
if(x == n) return;
if(x == 0) a[x] = 0;
if(x == 1) a[x] = 1;
if(x >= 2) a[x] = a[x - 1] + a[x - 2];
dfs(x + 1);
}
int main()
{
cin>>n;
dfs(0);
for(int i = 0;i < n; i ++)
{
cout<<a[i]<<" ";
}
return 0;
}