Dominoes Shop SquaresTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 42774 Accepted Submission (s): 20735
Problem description in a rectangular square of 2xn, fill the squares with a 1x2 domino, enter N, and output the total number of paving schemes.
For example, when n=3, for 2x3 squares, the Domino placement scheme has three kinds, such as:
Input data consists of multiple lines, each containing an integer n, indicating that the size of the rectangular square of the test instance is 2xn (0<n<=50).
Output for each test instance, export the total number of tiling schemes, one row for each instance.
Sample Input
132
Sample Output
132
Authorlcy
Source Recursive Solution topic exercise (for beginner)
original title link: http://acm.hdu.edu.cn/showproblem.php?pid=2046
A look is a recursivewhen you put N, you can put two pieces on the far right side of the n-2, and there are a[n-2] kinds of situations,can also be in the case of n-1 in the right vertical put a piece, there are a[n-1] kind of situation.therefore: a[n]=a[n-2]+a[n-1]
AC Code:
#include <iostream>using namespace Std;int main () { long Long a[55]={0,1,2}; for (int i=3;i<55;i++) a[i]=a[i-1]+a[i-2]; int n; while (Cin>>n) { cout<<a[n]<<endl; } return 0;}
HDU 2046 Dominoes paved squares (recursive)