algorithm Training Tile Pavingtime limit: 1.0s memory limit: 512.0MBThe 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
ImportJava.util.Scanner; Public classMain {Static intN; Static intResult=0; Static voidGetResult (intLen) { if(len==N) {result++; return ;} if(len>N)return; if(len+1<=N) getresult (len+1); if(len+2<=N) getresult (len+2); } Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in); N=Sc.nextint (); intLen=0; GetResult (len); SYSTEM.OUT.PRINTLN (result); }}
Algorithm Training Tile Paving