790. Domino and Tromino Tiling
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
XGiven 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
Note:
- N will be in range
[1, 1000].
Approach #1: DP. [C++]
class Solution {
public:
int numTilings(int N) {
constexpr int mod = 1000000007;
vector<vector<long>> dp(N+1, vector<long>(2, 0));
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] + 2 * dp[i-1][1]) % mod;
dp[i][1] = (dp[i-2][0] + dp[i-1][1]) % mod;
}
return dp[N][0];
}
};
Analysis:
http://zxi.mytechroad.com/blog/dynamic-programming/leetcode-790-domino-and-tromino-tiling/
790. Domino and Tromino Tiling的更多相关文章
- leetcode 790. Domino and Tromino Tiling
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...
- 【LeetCode】790. Domino and Tromino Tiling 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/domino-a ...
- [Swift]LeetCode790. 多米诺和托米诺平铺 | Domino and Tromino Tiling
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...
- [LeetCode] Domino and Tromino Tiling 多米诺和三格骨牌
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...
- 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 ...
- 动态规划-填格子问题 Domino and Tromino Tiling
2018-09-01 22:38:19 问题描述: 问题求解: 本题如果是第一看到,应该还是非常棘手的,基本没有什么思路. 不妨先从一种简化的版本来考虑.如果仅有一种砖块,那么,填充的方式如下.
- leetcode790 Domino and Tromino Tiling
思路: dp.没有像discuss中的那样优化递推式. 实现: class Solution { public: ; int numTilings(int N) { vector<vector& ...
- LeetCode All in One题解汇总(持续更新中...)
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
- leetcode 学习心得 (4)
645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...
随机推荐
- kafka 报Failed to load class "org.slf4j.impl.StaticLoggerBinder".[z]
转:http://blog.chinaunix.net/uid-25135004-id-4172954.html 测试kafka producer发送消息 和 consumer 接受消息报错 ...
- laravel创建控制器
一.创建 php artisan make:controller Admin/IndexController 二.目录 app/Http/Controllers/ 控制器存储目录 [ C控制器 ]
- Java数据结构和算法(三)顺序存储的树结构
Java数据结构和算法(三)顺序存储的树结构 二叉树也可以用数组存储,可以和完全二叉树的节点一一对应. 一.树的遍历 // 二叉树保存在数组中 int[] data; public void preO ...
- c++11日志练习
/************************************************************** 技术博客 http://www.cnblogs.com/itdef/ ...
- apicloud管理
以下所有操作都是指“apicloud”平台下的管理: 1. 一定要记得备份证书.证书不是因为你记得别名和密码就能还原的.因为apicloud是服务器session存数据,千万不要打开多个app操作页面 ...
- javascript札记
bind和unbind对应,live和die对应,千万别用bind绑定,用die解除.还有bind可以多次绑定同一个函数,可能会被执行多次同一个函数 正则表达式的使用 var email_reg = ...
- 用pyqt5做一个能python程序能插入图片的ide
之前只是放到github上了,现在一想应该开源,大家想继续做好这个ide的都能从这里起步. #注意在.py文件相同目录下放一个1.png做测试图片 #本质就是用html来实现图片 #写在前面的话:这个 ...
- C语言基础第三次作业
题目7-1,寻找最小值 1.实验代码: #include<stdio.h> int main() { int i,mark,min,n; scanf("%d", &am ...
- 2018.07.27 bzoj3064: Tyvj 1518 CPU监控(线段树)
传送门 线段树好题. 维护区间加,区间覆盖,区间最大,区间历史最大. 这个东西在国家集训队2016论文集之<区间最值操作与历史最值问题--杭州学军中学 吉如一>中讲的已经很详细了. 简单来 ...
- 2018.07.18 洛谷P1171 售货员的难题(状压dp)
传送门 感觉是一道经典的状压dp,随便写了一发卡了卡常数开了个O(2)" role="presentation" style="position: relati ...