递推POJ2663
来源:互联网 发布:暴力营销软件 编辑:程序博客网 时间:2024/05/16 17:05
Tri Tiling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10549 Accepted: 5347
Description
In how many ways can you tile a 3xn rectangle with 2x1 dominoes?
Here is a sample tiling of a 3x12 rectangle.
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
2812-1
Sample Output
31532131
这个题目开始以为跟POJ2506一样,首先,n等于奇数的时候3n也是奇数,所以是0种排法。然后就考虑把格子分成3×2+3×(n-2)、3×4+3×(n-4)来看,3×2有三种摆法,3×4有两种摆法,然后就得到了dp方程,F(n)=3F(n-2)+2F(n-4).结果写出来发现结果不对,然后我又多画了几组,然后就发现n>=4后又会多出小单位组成的大单位(6、9、12.块等)处也有衔接,然后就把它们加入了dp方程中,就成了F(n)=3F(n-2)+2(F(n-4)+F(n-6)+……+F(2)),然后再写一步F(n-2)=3F(n-4)+2(F(n-6)+F(n-8)+……+F(2)),两个式子相减就可以得到关系式F(n)=4×F(n-2)-F(n-4)。以下是我的代码#include<stdio.h>int main (){ int T; long long arr[35]; arr[2]=3; arr[4]=11; for(int i=6;i<35;i+=2) arr[i]=4*arr[i-2]-arr[i-4]; while(~scanf("%d",&T)&&T!=-1) { if(T%2!=0) printf("0\n"); else printf("%d\n",arr[T]); } return 0;}一次AC。
0 0
- poj2663 递推
- poj2663递推思想
- 递推POJ2663
- POJ2663(矩阵+递推)
- poj2663 Tri Tiling dp递推
- POJ2663
- poj2663
- poj2663 分治
- POJ2663 完美覆盖
- POJ2663——Tri Tiling
- poj2663 Tri Tiling dp 水题
- [POJ2663]Tri Tiling(dp)
- HDU 1143Tri Tiling&&POJ2663
- 递推
- 递推
- 递推
- 递推
- 递推
- GIT篇之如何删除github上的仓库?
- js继承的三种方式
- JAVA中常用的数据结构
- openvSwtich学习(2)—— 网络基础知识
- Numpy学习笔记(一)
- 递推POJ2663
- MBCS,UNICODE,UTF-8之间的转换
- 多线程 生产者消费者模式 线程之间的通讯问题
- All packages are not available for download! The following packages are not available:
- 活动选择
- Java中将字符串变成字符(字节)串,并且遍历的两种方法
- 122. Best Time to Buy and Sell Stock II
- 文件压缩
- getElementById与IE6