We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.

XX  <- domino

XX  <- "L" tromino
X

Given N, how many ways are there to tile a 2 x N board? Return your answer modulo 10^9 + 7.

(In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.)

Example:
Input: 3
Output: 5
Explanation:
The five different ways are listed below, different letters indicates different tiles:
XYZ XXZ XYY XXY XYY
XYZ YYZ XZZ XYY XXY

思路:分3个状态,第i列上边凸出,下边凸出,和平的。如图,那么状态转换如图中公式。



转载注明出处http://www.cnblogs.com/pk28/p/8470177.html

class Solution {
public:
const int mod = 1000000007;
int dp[1100][3];
int numTilings(int N) {
dp[0][0] = dp[1][0] = 1;
for (int i = 2; i <= N; ++i) {
dp[i][0] = ((dp[i-1][0] + dp[i-2][0])%mod + (dp[i-1][1] + dp[i-1][2])%mod)%mod;
dp[i][1] = (dp[i-2][0] + dp[i-1][2])%mod;
dp[i][2] = (dp[i-2][0] + dp[i-1][1])%mod;
}
return dp[N][0];
}
};

leetcode 790. Domino and Tromino Tiling的更多相关文章

  1. 【LeetCode】790. Domino and Tromino Tiling 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/domino-a ...

  2. 790. Domino and Tromino Tiling

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  3. [LeetCode] Domino and Tromino Tiling 多米诺和三格骨牌

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  4. 73th LeetCode Weekly Contest Domino and Tromino Tiling

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  5. [Swift]LeetCode790. 多米诺和托米诺平铺 | Domino and Tromino Tiling

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  6. 动态规划-填格子问题 Domino and Tromino Tiling

    2018-09-01 22:38:19 问题描述: 问题求解: 本题如果是第一看到,应该还是非常棘手的,基本没有什么思路. 不妨先从一种简化的版本来考虑.如果仅有一种砖块,那么,填充的方式如下.

  7. leetcode790 Domino and Tromino Tiling

    思路: dp.没有像discuss中的那样优化递推式. 实现: class Solution { public: ; int numTilings(int N) { vector<vector& ...

  8. Leetcode: Minimum Domino Rotations For Equal Row

    In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domin ...

  9. Java实现 LeetCode 790 多米诺和托米诺平铺(递推)

    790. 多米诺和托米诺平铺 有两种形状的瓷砖:一种是 2x1 的多米诺形,另一种是形如 "L" 的托米诺形.两种形状都可以旋转. XX <- 多米诺 XX <- &q ...

随机推荐

  1. django中表变更后migrate无效的问题

    问题描述: 已有的model,修改之后,想重新建模,于是将migrations文件夹中除__init__.py之外其他文件都删掉,再次执行以下步骤python manage.py makemigrat ...

  2. JS没有contains方法,可以用indexof实现

    我们很多时候会不自觉的在js代码里对一个字符串进行如下操作: str.contains("substr"); 但是js里面没有这个方法去判断字符串str是不是包含substr,而j ...

  3. 手机微硬盘读取速度>50MB/s eMMC技术浅析

    转载:http://mobile.zol.com.cn/296/2968659_all.html#p2968659 手机微硬盘读取速度>50MB/s 在开始今天的话题之前,请大家随笔者一起时光倒 ...

  4. ui develop

    https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/DesigningaUserInt ...

  5. 转: Android开发的网络抓包

    方法就是在android机器上面安装tcpdump,然后通过-w参数把抓包记录到本地,再把抓到的.cap文件导到pc上面用wireshark来分析.这里步骤非常多,在和后台联调的时候,这个效率是非常低 ...

  6. JavaScript技巧手冊

    js小技巧 每一项都是js中的小技巧,但十分的有用! 1.document.write(""); 输出语句  2.JS中的凝视为//  3.传统的HTML文档顺序是:documen ...

  7. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载一(PhoneGap中的API)

    之前本博连载过<构建跨平台APP:jQuery Mobile移动应用实战>一书.深受移动开发入门人员的喜爱. 从如今開始,连载它的孪生姐妹书phoneGap移动应用实战一书,希望以前是小白 ...

  8. react className 有多个值时的处理 / react 样式使用 百分比(%) 报错

    1.react className 有多个值时的处理 <fieldset className={`${styles.formFieldset} ${styles.formItem}`}> ...

  9. vue-router钩子beforeRouteEnter函数获取到this实例

    官方文档: const Foo = { template: `...`, beforeRouteEnter (to, from, next) { // 在渲染该组件的对应路由被 confirm 前调用 ...

  10. Odoo超售订单

    当 交付给客户的货物多于订购的数量时,就形成'超售'状态: 对于超售的部分,需要进行开票处理,以及根据情况修改交货     发生超售的前提是,产品开票策略为 '按订购数量开票'     同时需要 允许 ...