【POJ 2663】Tri Tiling(dp|递推)
2016-10-27 20:26
573 查看
Tri Tiling
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 |
[Discuss]
![](http://poj.org/images/home.gif)
Home Page
![](http://poj.org/images/goback.gif)
Go
Back
![](http://poj.org/images/top.gif)
To top
[题意][用1×2的小矩阵填充3×n,一共有多少种方法]
【题解】【递推】
【明明是dp,却硬生生的写成了递推 】
【完整的2*3矩形有3种拼法,所以f
+=3*f[n-2]。
当突出两块时:突出的两块时上侧两个:发现往后拼只有一种方法。突出的两块在下侧时同样一个,于是用这种突出的方法拼出f
有两种(就是以三个一组,两组并在一起时,将中间的两个竖放的改为横着的)。即f
+=2*(f[n-4]+f[n-6]+..+f[0]).
】
【于是f
=3*f[n-2]+2*(f[n-4]+..+f[0]),求通项得:f
=4*f[n-2]-f[n-4].】
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int f[40]; int main() { int i,j; f[0]=1; f[2]=3; for (i=4;i<=30;i+=2) f[i]=4*f[i-2]-f[i-4]; while (scanf("%d",&j)==1&&j!=-1) printf("%d\n",f[j]); return 0; }
相关文章推荐
- POJ-2663,2506 Tri Tiling 递推 | 压缩DP
- poj 2663 Tri Tiling 【简单数位DP】
- poj 2663 Tri Tiling(递推)
- POJ 2663 Tri Tiling 线性递推 矩阵快速幂
- poj 2663 Tri Tiling--状压dp
- POJ 2663 Tri Tiling 递推
- poj 2663 Tri Tiling 状压dp
- Tri Tiling - POJ 2663 递推
- POJ_1850_Code_DP,递推
- POJ 2663 Tri Tiling
- poj 2663 Tri Tiling dp(矩形填充)
- POJ-2663-Tri Tiling
- poj 2663 Tri Tiling
- poj 2663 Tri Tiling
- 【poj 3176】 Cow Bowling 递推dp
- POJ-2663-Tri Tiling
- POJ_2663_Tri Tiling_DFS,状态压缩,动态规划
- POJ 2663 Tri Tiling
- dp递推poj2801
- poj 2506 Tiling dp 递推