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