본문 바로가기

problem solving/Problem Solving

Tri Tiling


http://acm.pku.edu.cn/JudgeOnline/problem?id=2663

Description

In how many ways can you tile a 3xn rectangle with 2x1 dominoes?
Here is a sample tiling of a 3x12 rectangle.

Input

Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer 0 <= n <= 30.

Output

For each test case, output one integer number giving the number of possible tilings.

Source

Waterloo local 2005.09.24


Solving

n이 홀수일 때 가능한 모양이 없는 것은 자명하다.

n이 2일 때: 가능한 모양의 갯수는 3개이다.
n이 4일 때: 가능한 모양은 n-2=2일때의 갯수(3) * 3 + 4개가 모여 가능한 모양이 2개 = 총 11개이다.
n이 6일 때: 가능한 모양은 n-2=4일때의 갯수(11) * 3 +  n-4=2일때의갯수(3) * 4개 모양(2) + 6개 모양(2) = 41
n이 8일 때: n-2=6일때의 갯수(41) * 3 + n-4=4일때(11) * 4개 모양(2) + n-2=2일때(3) * 6개 모양(2) + 8개모양(2) = 153
...
위의 연구(?)를 바탕으로 점화식을 새워 DP로 문제를 해결할 수 있다.

'problem solving > Problem Solving' 카테고리의 다른 글

Ubiquitous Religions  (0) 2008.10.07
MPI Maelstrom  (0) 2008.10.07
4 Values whose Sum is 0  (0) 2008.10.07
Palindrome Numbers  (0) 2008.10.07
Sum of Factorials  (0) 2008.10.07