Sword refers to the offer series source-Rectangle Overlay

Source: Internet
Author: User

Topic 1390: Rectangular Coverage time limit: 1 seconds Memory limit: 32 Mega Special: No submission: 1409 resolution: 886 Title Description: We can use the small rectangle of 2*1 to cover the larger rectangle horizontally or vertically. What is the total number of ways to cover a large rectangle of 2*n with n 2*1 small rectangles without overlapping? Input: The input may contain multiple test samples, and for each test case, the input includes an integer n (1<=n<=70), where n is an even number. Output: For each test case, the output of the small rectangle with n 2*1 overlay a large rectangle of 2*n without overlapping, the total number of methods. Sample input: 4 Sample output: 5

#include <iostream> #include <stdio.h>using namespace std;//forwarding loop long  long f (int n) {    if (n==1) return 1;    if (n==2) return 2;    Long long sum=0;    Long Long preone=2;//n before a    long long pretwo=1;//n the first two for    (int i=3;i<=n;i++) {        sum = preone+pretwo;        Pretwo = PreOne;        PreOne = sum;    }    return sum;} int main () {    int n;    while (scanf ("%d", &n)!=eof) {        printf ("%ld\n", f (n));    }    return 0;}


Sword refers to the offer series source-Rectangle Overlay

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.