Problem Description
There is a floor with a length of N (1 <= N <= 10), given two different tiles: one with a length of 1 and another with a length of 2, the number is unlimited. How many different paving methods are needed to cover this floor of length N?
For example, the ground with a length of 4 has the following 5 types of paving methods:
4 = 1 + 1 + 1 + 1 + 1
4 = 2 + 1 + 1
4 = 1 + 2 + 1
4 = 1 + 1 + 2
4 = 2 + 2
Programming uses recursive methods to solve the above problems.
For example, the ground with a length of 4 has the following 5 types of paving methods:
4 = 1 + 1 + 1 + 1 + 1
4 = 2 + 1 + 1
4 = 1 + 2 + 1
4 = 1 + 1 + 2
4 = 2 + 2
Programming uses recursive methods to solve the above problems.
Input format
There is only one number N, representing the length of the floor
Output format
Output a number representing the total number of all different tile laying methods
Sample input
4
Sample output
5
Thinking more complicated, you can recur without brain.
1 #include <bits/stdc++.h> 2 using namespace std; 3 int fun(int n) { 4 if (n == 1) { 5 return 1; 6 } 7 if (n == 2) { 8 return 2; 9 } 10 return fun(n - 1) + fun(n - 2); 11 } 12 int main() { 13 int n; 14 cin >> n; 15 cout << fun(n) << endl; 16 return 0; 17 }