poj2663 分治
来源:互联网 发布:淘宝联盟qq群推广技巧 编辑:程序博客网 时间:2024/06/05 18:24
Tri Tiling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9133 Accepted: 4740
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
题意:一个3
思路:递推,先假设输入的数字模2变成一个单位 1 (因为奇数是不可以使用的,拼不满)。
有木块拼满一单位有3种可能,其他有2种可能,ans[i]表示当前的解:
第二种递归方法是用式子 2 写出来的
#include<stdio.h>int ans[35];int main(){ ans[0]=1;ans[1]=3; for(int i=2;i<=15;i++){ ans[i]=3*ans[i-1]; for(int j=0;j<i-1;j++){ ans[i]+=2*ans[j]; } } int n; while(scanf("%d",&n),n!=-1) { if(n%2!=0) printf("0\n"); else printf("%d\n",ans[n/2]); } return 0;}
#include<stdio.h>int ans[18];void deal(int x){ if(x==1||x==0) return ; deal(x-1); ans[x]=4*ans[x-1]-ans[x-2];}int main(){ ans[0]=1;ans[1]=3; deal(16); int n; while(scanf("%d",&n),n!=-1) { if(n%2!=0) printf("0\n"); else printf("%d\n",ans[n/2]); } return 0;}
0 0
- poj2663 分治
- POJ2663
- poj2663
- poj2663 递推
- POJ2663 完美覆盖
- poj2663递推思想
- 递推POJ2663
- POJ2663——Tri Tiling
- poj2663 Tri Tiling dp 水题
- [POJ2663]Tri Tiling(dp)
- POJ2663(矩阵+递推)
- HDU 1143Tri Tiling&&POJ2663
- poj2663 Tri Tiling dp递推
- Poj1185&Poj2411 状压dp(from Poj2663)
- 分治
- 分治
- 分治
- 分治
- jQuery重置select
- 【机房重构】Sqlhelper类解读
- Tomcat源码分析--启动过程
- 周易六十四卦——噬嗑卦
- leetcode——69——Sqrt(x)
- poj2663 分治
- JAVA集合类详解
- apk基础-反编译、打包、签名
- C++异常机制
- mybatis SQL性能调优
- Android中的线程和线程池
- hihocoder #1035 : 自驾旅行 III
- ReadWriteLock用法
- IOS原声二维码条形码扫描实现