The problem description has a length of n (1<=n<=10) of the floor, given two different tiles: one length of 1, the other a length of 2, an unlimited number. How many different paving methods are there to fill this n-length floor?
For example, a 4-length ground has the following 5 paving methods:
4=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 only one number n, representing the length of the floor output format output a number, representing the total number of all different tile paving methods sample input
4
Sample output
5
Analysis Process:
Find the law by recursion
1 1
2 2
3 1+1+1 1+2 2+1
5 1+1+1+1+1 2+1+1+1 1+2+1+1 1+1+2+1 1+1+1+2 2+2+1 2+1+2 1+2+2
Concludes that the total number of paving methods for each of the first two and
C Language code:
#include <stdio.h>intMain () {intn,m=1; intA=1, b=2; scanf ("%d",&N); if(n==1) {m=A; }Else if(n==2) {m=b; }Else{ for(intI=3; i<=n;i++) {m=a+b; A=b; b=m; }} printf ("%d", M); return 0;}
Blue Bridge Cup--algorithm training tile Paving