(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

Source: Internet
Author: User

(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 Input
32812
 
Sample Output
31712731
 
 
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 ;}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.