Description of the problem
has a length of N (1 <= N <= 10) of the floor, the given two different tiles: one kind of length 1, length 2 to another, the number is not limited. To this length N floor covered with a number of different lay-total?
For example, the length of the floor 4 of a total of the following five kinds of lay-:
4 = 1 + 1 + 1 + 1
4 = 2 + 1 + 1
4 = 1 + 2 + 1
4 = 1 + 1 + 2
4 = 2 + 2
programming for solving the above problem with the recursive method.
The input format
is only a number N, the representative length flooring
output format
outputs a number representative of all the different method of laying tiles total
sample input
4
Sample Output
5
Problem-solving ideas:
Dfs violence is found
#pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;} typedef long long ll; const int maxn = 1e5+10; int n; int sum; int ans; void dfs(int sum){ if(sum>n) return ; if(sum==n){ ans++; return ; } dfs(sum+1); dfs(sum+2); } int main () { cin>>n; dfs(0); printf("%d",ans); return 0; }