Tri Tiling (hdu1143)

Source: Internet
Author: User

Tri Tiling

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2731 Accepted Submission (s): 1547


Problem DescriptionIn How many ways can do tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle.



Inputinput consists of several test cases followed by a line containing-1. Each test case was a line containing an integer 0≤n≤30. 

Outputfor each test case, output one integer number giving the number of possible tilings. 

Sample Input
2812-1

Sample Output
31532131

Sourceuniversity of Waterloo Local Contest 2005.09.24
Ideas:

1. Marking and concept Description

F (n): where n is the length of the rectangle in the title, high fixed bit 3, that is, the title of the 3xn in the N,f (n) indicates that when the length of n, all the number of placement. Split Line: A vertical line that passes through a rectangle in the title, divides the rectangle in two, and the line cannot pass through the middle of the brick, meaning that only the edges of the bricks are aligned.

2. Thinking of solving problems

2.1 For each kind of brick placement situation, there may be a number of the above-mentioned split line, but for each case, we only need all the dividing line in the rightmost one, we remember as L. In other words, the right part of L is indivisible, but the left side may still be divisible. For the left of L we continue to use function f, and the right side is the main part that needs our research because the right cannot apply function f.

2.2 The reason why the function f cannot be applied is because the right side is not divisible. There are three ways to place an indivisible rectangle with a length of 2, and there are two ways of placing an indivisible rectangle with a length greater than 2. The understanding of the previous sentence may require you to draw a pen on a piece of paper.

2.3 At the same time, consider where this l might be? It may be 2 from the right, or it may be in the position of length 4, ..., or it may be in the position of length n. Of course, it is only possible in the above position,

Therefore, the following results are available:

F (n) =f (n-2) *3+f (n-4) *2+...+f (2) *2+f (0) * *----expression 1

Then, replace the n-2 with the following: F (n-2) =f (n-4) *3+f (n-6) *2+...+f (2) *2+f (0) * *----expression 2

expression 1 minus expression 2: F (n) =4*f (n-2)-F (n-4) 2.4 When using the recursive formula above, we need two recursive exits, i.e. f (0) = 1, f (2) = 3. By the above recursive formula also know that does not involve when n is an odd number of cases, when n is odd, directly to zero. Because when n is odd, the area of the rectangle is odd, but no matter how many bricks we use, the total area of the bricks must be an even number, so there is no form of placement.

Reprint Please specify the Source: Search & Star Children

Topic Links: http://acm.hdu.edu.cn/showproblem.php?pid=1143

There's a little bit of a hole in here I think. That is f[0]=1, why is it when the n=0 is 1???

#include <stdio.h> #define LL __int64ll ans[35];void init () {    ans[0]=1;    ans[1]=ans[3]=0;    ans[2]=3;ans[4]=11;    for (int i=5;i<=30;i++)    {        if (i&1) ans[i]=0;        else ans[i]=ans[i-2]*4-ans[i-4];}    } int main () {    int n;    Init ();    while (scanf ("%d", &n)!=eof)    {        if (n==-1) break;        printf ("%i64d\n", Ans[n]);    }    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Tri Tiling (hdu1143)

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.