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