Topic Links:
http://poj.org/problem?id=2506
Title Description:
There are 2*1 and 2*2 two kinds of porcelain pieces, asked how many ways to pave the 2*n graphics?
Problem Solving Ideas:
Using the recursive idea, the 2*n can be transferred from the state of the n-1 and a piece of vertical 2*1 porcelain, or by the state of the (n-2) plus a piece of 2*2 porcelain or two pieces of 2*1 horizontally.
Recursive formula can be derived: dp[n] = dp[n-1] + dp[n-2]*2;
AC Tips:
(1): From the output sample can be seen to use a large number to represent, probably need about 90 bits.
(2): 2*0 not 0 ways? After countless times WA, proved to be one, unexpectedly is a!!!!!!! , but also drunk, hard to think for a long.
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <iostream>5 using namespacestd;6 #defineMAXN 907 intdp[251][MAXN], A[MAXN];8 9 intMain ()Ten { One intN, I, J; AMemset (DP,0,sizeof(DP)); -dp[0][0] =1; -dp[1][0] =1; thedp[2][0] =3; - for(i=3; i<251; i++)//marking, storing all the results - { - intYu =0; + for(j=0; j<maxn; J + +)//Large number operation - { + ints = dp[i-2][j]*2+ Yu + dp[i-1][j]; ADP[I][J] = s%Ten; atYu = S/Ten; - } - } - while(SCANF ("%d", &n)! =EOF) - { -i = MAXN-1; in while(Dp[n][i] = =0)//remove leading 0 -i--; to for(; I >=0; i--) +printf ("%d", Dp[n][i]); -printf ("\ n"); the } * return 0; $}
POJ 2506 Tiling Recursion