Poj2663 Tri Tiling dp recurrence

Source: Internet
Author: User

Tiling
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submissions: 6314 Accepted: 3370
Description
In how many ways can you tile a 3xn rectangle with 2x1 dominoes?
Here is a sample tiling of a 3x12 rectangle.

Input
Input consists of several test cases followed by a line containing-1. Each test case is a line containing an integer 0 <= n <= 30.
Output
For each test case, output one integer number giving the number of possible tilings.
Sample Input
2
8
12
-1
Sample Output
3
153
2131
Source
Waterloo local 2005.09.24
 
Exercise thinking questions.
If n is an odd number, it must be 0, and n is an even number. Two columns are added each time. We can take the two columns as one column, if this column is separated from the front, there are only three methods, namely 3 * a [N-2]. If this column is not separated from the front, so there are only two kinds of non-decomposed rectangle, SO 2 * (a [n-4] + a [n-6] + ...... A [0])
Simplification is a [n] = 4 * a [N-2]-a [n-4]
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Define ll long
Using namespace std;
Ll a [31];
Int main ()
{
Ll n;
A [0] = 1; a [2] = 3;
For (int I = 4; I <= 30; I + = 2)
A [I] = 4 * a [I-2]-a [I-4];
While (scanf ("% lld", & n ))
{
If (n =-1) break;
Printf ("% lld \ n", a [n]);
}
}

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.