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喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
随机推荐
- JavaWeb跨域访问问题
转载: http://blog.csdn.net/zjq_1314520/article/details/65449279 最后的解决方案如下: 在 tomcat 的 conf目录下找到 web.xm ...
- python使用tkinter写带界面的工具
python一般用来写纯脚本的居多,但也可以做有视图的产品出来,例如做网页和客户端工具.做成工具的好处是,让不懂代码的人也能使用,不需要去修改代码里面的参数,如果使用次数频繁,甚至比纯脚本跟节约时间: ...
- mongodb 初学 目录
mongodb 初学 索引 啦啦啦 MongoDB 教程 NoSQL 简介 MongoDB 简介 Windows 平台安装 MongoDB Linux平台安装MongoDB mongodb 在 Ubu ...
- @ControllerAdvice -- 处理异常示例
Class : SessionInterceptor package com.estate.web.filter; import javax.annotation.Resource; import j ...
- CSS属性中display="none“与visibility="hidden"的不同
display="none",元素会从页面移除,不在页面占用位置,当某个元素设置为display="none"时,这个元素后面的元素会移动上来 visibili ...
- mybatis 之 parameterType="list"
<!-- 根据货品编号查找货品图片地址,货品ID,商品ID,货品名称 --> <select id="getGoodsInfoByGoodsNo" paramet ...
- C++ template —— 模板特化(五)
本篇讲解模板特化-------------------------------------------------------------------------------------------- ...
- <转>ML 相关算法参考
转自 国内外网站如果你想搜索比较新颖的机器学习资料或是文章,可以到以下网站中搜索,里面不仅包括了机器学习的内容,还有许多其它相关领域内容,如数据科学和云计算等.InfoWord:http://www. ...
- 【vue基础学习】vue.js开发环境搭建
1.安装node.js(http://www.runoob.com/nodejs/nodejs-install-setup.html) 2.基于node.js,利用淘宝npm镜像安装相关依赖 在cmd ...
- Android开发训练之第五章第三节——Transferring Data Without Draining the Battery
Transferring Data Without Draining the Battery GET STARTED DEPENDENCIES AND PREREQUISITES Android 2. ...