Subject description:
-
We can use a small rectangle 2 * 1 sideways or vertically to cover a larger rectangle. Will the small rectangle of n 2 * 1 coverage without overlap a large rectangle 2 * n, a total of how many ways?
Input:
-
Input may contain multiple test samples for each test case,
Input comprises an integer n (1 <= n <= 70), where n is an even number.
Output:
-
Corresponding to each test case,
Outputting the small rectangle 2 * n-1 non-overlapping covers a large rectangle 2 * n, the total number of conventional method.
Sample input:
-
4
Sample output:
- 5
Problem-solving ideas:
- Observation of the title rectangle, 2 * n, is a long strip. Originally imagine the brain is complex Huarong, but now simply a long strip, then still reverse analysis. Since it is elongated, then from back to front, and finally a rectangular 2 * 2, only two cases:
- The first is the last of a rectangular (n-1) of a rectangle plus a 2 * 2 * 1 bristling
- Another is a 2 * (n-2) is rectangular, with two rectangular sideways 2 * 1
- So we can conclude,
- 2 * n of the rectangular cover of the method is equal to 2 * (n-1) plus Method 2 * (n-2) a . Using the code can be expressed as:
for(i=3;i<71;i++){
arr[i] = arr[i-1]+arr[i-2];
}
Still have to pay attention to the data type, as long long type
Code:
#include <stdio.h>
long long arr[71] = {0,1,2};
void createArr(void){
int i;
for(i=3;i<71;i++){
arr[i] = arr[i-1]+arr[i-2];
}
}
int main(void){
int n;
createArr();
while(scanf("%d",&n) != EOF && n>=1 && n<=70){
printf("%lld\n",arr[n]);
}
return 0;
}
/**************************************************************
Problem: 1390
User: xhalo
Language: C
Result: Accepted
Time:0 ms
Memory:916 kb
****************************************************************/
Reproduced in: https: //my.oschina.net/u/204616/blog/545134