[HDU] [2046] Domino Tiling

Problem Description

Loading...

Problem Analysis

For the n-th one, it can come from the (n-1)-th arrangement plus one vertical domino, or from the (n-2)-th arrangement with two horizontal dominoes
So f(n) = 1×f(n-1) + 1×f(n-2);

So it is similar to the Fibonacci sequence

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include<stdio.h>
__int64 a[55];
int main() {
	a[1]=1,a[2]=2;
	for(int i=3; i<52; i++)
		a[i]=a[i-1]+a[i-2];
	int n;
	while(scanf("%d",&n)!=EOF) {
		printf("%I64d\n",a[n]);
	}
	return 0;
}

Problem link:【HDU】[2046] Domino Paving Squares

Loading...