(Hdu step 3.1.5) Tiling_easy version (calculate the number of grid solutions with 2x1 and 2x2 bone cells filled with 2 x n), hdutiling_easy
Make an advertisement for yourself before writing a question ~.. Sorry, I hope you can support my CSDN video courses at the following address:
Http://edu.csdn.net/course/detail/209
Question:
Tiling_easy version |
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission (s): 515 Accepted Submission (s): 447 |
|
Problem Description has a grid of 2 x n, and now we need to fill it with two types of dominoes, which are 2x1 and 2x2, respectively, calculate the total number of laying methods. |
The first line of Input contains a positive integer T (T <= 20), indicating a total of T groups of data, followed by T rows of data, each row contains a positive integer N (N <= 30), indicating that the grid size is two rows and N columns. |
How many laying methods are Output, and the Output of each group of data occupies one row. |
Sample Input32812 |
Sample Output31712731 |
|
Source ACM Short Term Exams _ software engineering and other majors |
Recommendlcy |
Question Analysis:
Simple recursion. In fact, this question is quite similar to "hdu step 3.1.2)", but it only adds a type of bone lattice. But the idea is the same.
The Code is as follows:
/** E. cpp ** Created on: February 5, 2015 * Author: Administrator */# include <iostream> # include <cstdio> using namespace std; const int maxn = 33; int dp [maxn]; void prepare () {dp [1] = 1; dp [2] = 3; int I; for (I = 3; I <maxn; ++ I) {dp [I] = dp [I-1] + dp [I-2] * 2; // This time is dp [I-2] * 2. because the last 2*2 bone cells can be solved by two horizontally placed 2*1, or by a 2*2 filled} int main () {prepare (); int t; scanf ("% d", & t); while (t --) {int n; scanf ("% d", & n ); printf ("% d \ n", dp [n]);} return 0 ;}