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 ...
随机推荐
- 启动apache时,出现httpd: Could not reliably determine the server\'s fully qualified domain name, using 127.0.0.1 for ServerName
1.通过vi打开apache的配置文件httpd.conf > vi /data/apache/conf/httpd.conf 2.找到#ServerName www.example.com:8 ...
- iOS开发总结
最近在工作中使用Objective-C开发iOS客户端程序,它一方面和Server通讯,处理网络连接,收发报文,实现业务逻辑;另一方面为UI层提供各种业务API. 下面记录用到的相关知识点,困难, ...
- Apache虚拟主机/端口多开
Apache就是强大啊,简单配置一下就可以再开启另一个端口的web服务. 笔者最近使用XAMPP架设php服务端.有一些特别的需求:同样的代码,需要开始不同的端口, 协议类型提供web服务给客户端(h ...
- mvcpager 表单提交时无法获取pageindex的值
1.将分布页包含到form中 2.在分布页中新增一个表单hidden元素,name为pageIndex(与控制器中的pageindex保持一尺),将后台获取到的pageindex值通过viewbag初 ...
- geoserver 通过代码实现发布地图服务
GeoServer:代码实现批量发布地图服务 利用GeoServer发布WCS服务,那么如果我有很多数据需要进行发布,这样利用GeoServer提供的UI界面进行操作显然很不显示.那能不能利用GeoS ...
- VMware下的Linux系统中Windows的共享目录,不支持创建软连接
[问题] 在编译VMware下的Linux系统对从Windows中共享过来的文件,进行编译的时候,遇到: ln: creating symbolic link XXXXXX : Operation ...
- Laravel 5.x 启动过程分析
Posted on 2015年9月11日 by 学院君 1.初始化Application 1.1 注册基本绑定 app -> Application实例(Illuminate\Foundat ...
- org.apache.commons札记
StringUtils.isBlank(null); //trueStringUtils.isBlank(""); //trueStringUtils.isBlank(" ...
- Python中的编码和解码问题
关于Python中遇到的中文字符串的读取和输入时总是遇到一堆问题,到现在还不是特别明白,只是有了一个大概率的理解,就是:字符串是用什么编码格式编码的,就用什么编码格式来解码. encode()对字符串 ...
- 2018.09.15[POI2008]BLO-Blockade(割点)
描述 There are exactly nn towns in Byteotia. Some towns are connected by bidirectional roads. There ar ...