Tile problem: Hdu 2046 Domino box + POJ 2663 Tri tiling (Recursive)

Source: Internet
Author: User
Tags time limit

Domino Grid

http://acm.hdu.edu.cn/showproblem.php?pid=2046

Time limit:2000/1000 MS (java/others)

Memory limit:65536/32768 K (java/others)

Problem Description

In a rectangular square box of 2xn, a 1x2 domino is filled with squares, input n, and the total number of output placement schemes. For example, when the n=3, for the 2x3 Square, Domino's placement scheme has three kinds, the following figure:

Input

The input data consists of multiple lines, each containing an integer n, which indicates that the rectangular square of the test instance is 2xn (0<n<=50).

Output

For each test instance, output the total number of placement scenarios, one row for each instance.

Sample Input

132

Sample Output

132

Idea: N-length dominoes, from n-1-length dominoes + rightmost vertical, and n-2-length dominoes + rightmost two-lateral. So it's the Fibonacci relationship.

Note that the n=50 will be super Int.

Complete code:

/*15ms,208kb*/
    
#include <cstdio>  
    
long long f[52];  
    
int main ()  
{  
    int n, i;  
    F[1] = f[2] = 1;  
    for (i = 3; i < ++i) f[i] = F[i-1] + f[i-2];  
    while (~SCANF ("%d", &n))  
        printf ("%i64d\n", F[n + 1));  
    return 0;  
}

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45514.htm

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.