POJ 2663 Tri Tiling 递推
2015-12-18 15:00
351 查看
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]
算出前8个找规律,当n为奇数时候方案为0,当n为偶数时 f(n)=4*f(n-2)-f(n-4) n>=4
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制
#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 100005
#define mod 1000000007
#define INF 0x3f3f3f3f //int 最大值
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI acos(-1.0)
#define E exp(1)
using namespace std;
int ans[maxn],n;
void init(){
MT(ans,0);
ans[0]=1;
ans[2]=3;
for(int i=4;i<33;i+=2)
ans[i]=ans[i-2]*4-ans[i-4];
}
void doit(){
printf("%d\n",ans
);
}
int main(){
init();
while(rd(n)&&n+1)
doit();
return 0;
}
/*
2 8 12 -1*/
相关文章推荐
- MySQL Study之--Index强制和忽略
- jenkins全局安全设置
- Android 4.4.4 -Andoird 5.0.0代理(ProxySlector 中select函数)导致的BUG分析
- android下拉弹出框
- JVM虚拟机:JDK监控和故障处理工具
- js 解析json
- Win10怎么调整输入法的顺序?Win10调整输入法顺序的方法
- Android ListView OnItemLongClick和OnItemClick事件内部细节分享以及几个比较特别的属性
- iOS面试、笔试题目总结
- 陈皓:程序员技术练级攻略
- oracle 根据出生日期计算精确年龄
- TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error:
- Spark SQL 官方文档-中文翻译
- ORACLE 36进制和10进制,互相转换函数
- 演示JAVA自带DOM解析XML功能
- 微信支付 Unable to instantiate receiver net.sourceforge.simcpux.AppRegister
- 排列组合知识
- 关于生成验证码
- KEIL编译STM32程序出现test.sct(7): error: L6236E: No section matches&nbs
- 读写ini配置文件