Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1992
Test instructions: How many ways to pave 4*w squares with small rectangles of 1*2 and 2*1.
Analysis: If the newly added 1 columns, this column is vertical, there must be a[i] species, if the last added block to cross the right side of the boundary, not across to the penultimate column, then there is 4*a[i-2]; When crossing the right two boundary, there is no crossing the third boundary, there are 2*a[i-3] species, When the last three lines across the same time, there is no cross-fourth boundary, the simulation found that there are 3*a[i-4] species, that is, when the same time across the odd T-bar boundary, there is 2*a[i-t];t is even when there is 3*a[i=t]; so found a[i]=a[i-1]+4*a[i-2]+2*a[i-3 ]+3*a[i-4]+......+a[i-i]*b (i is an odd b=2, even b=3).
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 10010using namespacestd; LL a[1010];voidinit () {a[0]=1; a[1]=1; a[2]=5; a[3]= One; for(intI=4; i<= -; i++) {LL sum=a[i-1]+4*a[i-2]; LL b=2; for(intj=i-3; j>=0; j--) {sum+=a[j]*b; if(b==2) b++; Elseb--; } A[i]=sum; }}intMain () {intt,n,cas=1; Init (); scanf ("%d",&t); while(t--) {scanf ("%d",&N); printf ("%d%i64d\n", cas++, A[n]); }}View Code
hdu1992 (Recursive)