1283: Domino Square (zzuli)

Problem Description

In a rectangular square of 2 × n, fill the square with a 1 × 2 domino, input n, and output the total number of laying schemes.
For example, when n=3, it is a 2 × 3 square, the laying of dominoes There are three options, as shown below:
Input
The input data consists of multiple lines, each line contains an integer n, and the size of the rectangle representing the test instance is 2×n (0<n<=50).
Output
For each test instance, output the total number of placement scenarios, one line per instance.
Sample Input
1 3 2
Sample Output
1 3 2
Author
lcy
Source
Yeah, the value of this question is pretty good, although it was written after seeing the solution of the big guy, but at least the code was written by himself;
The original words of the big man:
Just a simple inference~
   Assuming that arr[i] is used to represent the total number of methods composed of 2*i squares, we know that arr[1]=1;arr[2]=2;
   Now suppose we already know arr[i-1] and arr[i-2], find arr[i], the so-called arr[i], just add a grid 2 after the grid of 2*(i-1) *1 square, the dominoes are placed horizontally and vertically on this square. If the i-1 block in front has been laid, there is only one way to lay the i-th block, which is to place it vertically. If it is to be placed horizontally, There is only one paving method, but it requires that the i-2 blocks in front have been paved!
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<map>
 4 using namespace std;
 5 int main()
 6 {
 7     int n;
 8     long long s[100];
 9     s[0] = 1, s[1] = 1;
10     for (int i = 2; i <= 50; i++)
11     {
12         s[i] = s[i - 1] + s[i - 2];
13     }
14     while (~scanf("%d", &n))
15     {
16         printf("%ld\n", s[n]);
17     }
18     return 0;
19 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325167883&siteId=291194637
Recommended