poj2663 Tri Tiling

Tri TilingTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5843Accepted: 3128

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.

Sample Input

2

8

12

-1

Sample Output

3

153

2131

Source

Waterloo local 2005.09.24

__________________________________________________________

(参考Matrix67,图片源自Matrix67);

共8个状态,建图如上,进行n+1次矩阵乘法,然后 000—>111为答案。

__________________________________________________________

 1 Program Stone;
 2
 3 const a:array[1..8,1..8]of longint=((0,0,0,0,0,1,0,0),
 4
 5                                     (0,0,0,0,1,0,0,0),
 6
 7                                     (0,0,0,0,0,1,0,1),
 8
 9                                     (0,0,0,0,0,0,1,0),
10
11                                     (0,1,0,0,0,1,0,0),
12
13                                     (1,0,1,0,1,0,0,0),
14
15                                     (0,0,0,1,0,0,0,0),
16
17                                     (0,0,1,0,0,0,0,0));
18
19 type ar=array[1..8,1..8]of longint;
20
21 var i,j,k,l,n:longint;
22
23     qu,ti:ar;
24
25
26
27  Procedure time(a,b:ar);
28
29  var i,j,k:longint;
30
31   begin
32
33     fillchar(ti,sizeof(ti),0);
34
35     for i:=1 to 8 do
36
37      for j:=1 to 8 do
38
39       for k:=1 to 8 do
40
41        inc(ti[i,j],a[i,k]*b[k,j]);
42
43   end;
44
45
46
47  Procedure quick(k:longint);
48
49   begin
50
51    if k=1 then begin qu:=a;exit;end;
52
53    quick(k div 2);
54
55    time(qu,qu);
56
57    if k mod 2<>0 then time(ti,a);
58
59    qu:=ti;
60
61   end;
62
63
64
65 Begin
66
67  assign(input,‘input.in‘);reset(input);
68
69   readln(n);
70
71   while n<>-1 do
72
73    begin
74
75     quick(n+1);
76
77     writeln(qu[1,6]);
78
79     readln(n);
80
81    end;
82
83  close(input);
84
85 end.
时间: 2024-12-19 04:25:53

poj2663 Tri Tiling的相关文章

poj2663 Tri Tiling dp 水题

用2个组合为3种情况,4,6,8......为2种情况 #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 40 ; typedef long long ll ; ll a[maxn] ; ll dp[maxn] ; int main() { // freopen("in.txt","r",stdi

POJ 2663 Tri Tiling

Tri Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10306   Accepted: 5237 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

Tri Tiling(hdu1143)

Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2731    Accepted Submission(s): 1547 Problem Description In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sa

I - Tri Tiling

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status 1 #include<cstdio> 2 using namespace std; 3 int f(int n) 4 { 5 if(n==0) 6 return 1; 7 if(n==2) 8 return 3; 9 else 10 return 4*f(n-2)-f(n-4); 11 } 12 int m

Tri Tiling

Tri Tiling 三瓷砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2676    Accepted Submission(s): 1511 Problem Description In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is

HDU 1143 Tri Tiling (递推)

Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2118    Accepted Submission(s): 1211 Problem Description In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sa

HDU 1143 Tri Tiling

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1143 Tri Tiling Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2799 Accepted Submission(s): 1585 Problem Description In how many ways can you tile a 3

poj 2663 Tri Tiling 状压dp

题意: 给3*N(N<=30)的矩形,问有多少种用1*2的小矩形铺满的方案. 分析: 同poj2411. 代码: #include <iostream> using namespace std; __int64 ans[32][4]; int n,m; __int64 dp[2][1<<4]; __int64 solve() { int i,j,used; memset(dp,0,sizeof(dp)); __int64 *crt=dp[0],*nxt=dp[1]; crt[

POJ 2663 Tri Tiling dp 画图找规律

状态:d[i]代表n=i时的方案数. 状态转移方程:d[i]=d[i-2]+2*(d[i-2]+d[i-4]+…+d[0]) i只会为偶数,奇数情况不存在,d[0]=1 找状态转移方程的时候画图更好理解. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int d[50]; int main() { int n; d[0]=1; d[2]=3; int sum