HOJ 2124 &POJ 2663Tri Tiling(动态规划)
Tri Tiling
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9016 Accepted: 4684
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
之前也写过这种堆方块,就是找递推的方程,还是比较简单的题目。但是这道题目却是一个升级,因为他的递推方程需要变形,所以以后遇到这类题目就又多了一点见识。
dp[n]=3*dp[n-2]+2*dp[n-4]+2*dp[n-6]+……2*dp[0];
如果只拿这个方程去解肯定麻烦或者还可能超时
变形
dp[n-2]=3*dp[n-4]+2*(dp[n-6]+dp[n-8]+…..dp[0]);
dp[n-2]-dp[n-4]=2*(dp[n-4]+dp[n-6]+dp[n-8]+….dp[0]);
dp[n]=4*dp[n-2]-dp[n-4];
就搞定了,
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int dp[35];
int n;
int main()
{
dp[0]=1;
dp[1]=0;
dp[2]=3;
for(int i=3;i<=30;i++)
{
if(i&1)
dp[i]=0;
else
dp[i]=dp[i-2]*4-dp[i-4];
}
while(scanf("%d",&n)!=EOF)
{
if(n==-1)
break;
printf("%d\n",dp[n]);
}
return 0;
}
HOJ 2124 &POJ 2663Tri Tiling(动态规划)的更多相关文章
- poj 3783 Balls 动态规划 100层楼投鸡蛋问题
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098409.html 题目链接:poj 3783 Balls 动态规划 100层楼投鸡蛋问题 ...
- HOJ 2133&POJ 2964 Tourist(动态规划)
Tourist Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1503 Accepted: 617 Description A ...
- HOJ 2148&POJ 2680(DP递推,加大数运算)
Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...
- POJ 1609 Tiling Up Blocks
Tiling Up Blocks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4675 Accepted: 1824 ...
- poj 2229 一道动态规划思维题
http://poj.org/problem?id=2229 先把题目连接发上.题目的意思就是: 把n拆分为2的幂相加的形式,问有多少种拆分方法. 看了大佬的完全背包代码很久都没懂,就照着网上的写了动 ...
- [POJ 2063] Investment (动态规划)
题目链接:http://poj.org/problem?id=2063 题意:银行每年提供d种债券,每种债券需要付出p[i]块钱,然后一年的收入是v[i],到期后我们把本金+收入取出来作为下一年度本金 ...
- [POJ 2923] Relocation (动态规划 状态压缩)
题目链接:http://poj.org/problem?id=2923 题目的大概意思是,有两辆车a和b,a车的最大承重为A,b车的最大承重为B.有n个家具需要从一个地方搬运到另一个地方,两辆车同时开 ...
- poj 2506 Tiling(递推 大数)
题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...
- POJ 1088 滑雪 -- 动态规划
题目地址:http://poj.org/problem?id=1088 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
随机推荐
- 中证500等主要指数的市盈率(PE)估值高度
全指医药(SH000991) - 2018-10-18日,当前值:22.8575,平均值:36.88,中位数:36.27655,当前 接近历史新低.全指医药(SH000991)的历史市盈率PE详情 中 ...
- nano-sql.js的基本操作
nano-sql是一个小而快的数据库引擎, 他支持联合查询, 分组, 事务, ORM等功能, 支持 内存, indeedDB, Local Storage, WebSQL, Level DB 注意第一 ...
- HTML5标签canvas图像处理
摘要: canvas可以读取图片后,使用drawImage方法在画布内进行重绘.本文介绍canvas的图像处理 drawImage drawImage() 方法在画布上绘制图像.画布或视频.drawI ...
- 页面倒计时跳转页面效果,js倒计时效果
页面倒计时跳转页面效果,js倒计时效果 >>>>>>>>>>>>>>>>>>>> ...
- RF-For循环使用
场景1:
- Kafka(二)-- 安装配置
一.单机部署 1.下载kafka,可在apache官网上下载,kafka要和JDK版本对应,我使用的是JDK1.7,kafka为0.10 2.进入到 /usr/java 中,解压到 此文件夹中 tar ...
- Tiny6410 关于制作ubifs文件系统映像
Tiny6410的superboot设计使得我不能用yaffs2文件系统,不过也罢,费点事就费点事吧 在这之前要安装mktools系列工具哦~~ 进入工作目录/opt/FriendlyARM/mini ...
- [Linux] 如何修改 Linux 主机名
该方法适用于安装了 Linux 系统的Raspberry Pi & Cubieboard. 在终端执行: sudo vi /etc/hosts 你看到的 hosts 文件应该是这样的: 127 ...
- Python内置性能分析模块timeit
timeit模块 timeit模块可以用来测试一小段Python代码的执行速度. class timeit.Timer(stmt='pass', setup='pass', timer=<tim ...
- UVA 10120 - Gift?!(搜索+规律)
Problem D. Gift?! The Problem There is a beautiful river in a small village. N rocks are arranged ...