HDU 1143 Tri TILING__DP

Source: Internet
Author: User
Tri Tiling Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2168 accepted Submission (s): 1240


Problem Description in many ways can, tile a 3xn rectangle with 2x1 dominoes? This is a sample tiling of 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 University of Waterloo local Contest 2005.09.24 Solution: The 3*n of the floor can be 1*2 by the board seamless splicing of the number of programs, first n of the odd time is certainly unable to splice, when n is even when, the whole as f[i] by the j*3 and F[i-j] two parts, j*3 part is not by the 2*3 splicing of the scheme species number, j= At 2, there are only 3 scenarios, and there are 2 options when j!=2
#include <cstdio>
int main ()
{
    int f[31];
    int i,j;
    int n;


    F[0]=1;
    for (i=1;i<=30;i+=2)    f[i]=0;
    for (i=2;i<=30;i+=2)
    {
        f[i]=0;
        for (j=2;j<=i;j+=2)
        {
            if (j==2)    f[i]+=3*f[i-j];
            else        f[i]+=2*f[i-j];
        }
    Freopen ("In.txt", "R", stdin);
    Freopen ("OUT.txt", "w", stdout);

    while (scanf ("%d", &n), n!=-1)    printf ("%d\n", F[n]);
    return 0;
}


Related Keywords:

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.