73th LeetCode Weekly Contest Domino and Tromino Tiling
2018-03-03 22:41
453 查看
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.
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.)
Note:
N will be in range
一块区域有--,L(上下两种位置),问2*N有几种放置方式。
首先
x 这种我们叫0
x
x这种我们叫1
xx
xx这种我们叫2
x
xxx是怎么得到的呢。一种是x+横着和竖着 xx+竖着 xx+L形(上下两种)
xxx x xx x
于是...dp[i][0]=dp[i-2][0]+dp[i-1][0]+dp[i-1][1]+dp[i-1][2] i表示列数啦
xxxx是怎么得到的呢。xx+L xx+ --
xxx xx xxx
dp[i][1]=dp[i-2][0]+dp[i-1][2]
xxx同理
xxxx
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
Note:
N will be in range
[1, 1000].
一块区域有--,L(上下两种位置),问2*N有几种放置方式。
首先
x 这种我们叫0
x
x这种我们叫1
xx
xx这种我们叫2
x
xxx是怎么得到的呢。一种是x+横着和竖着 xx+竖着 xx+L形(上下两种)
xxx x xx x
于是...dp[i][0]=dp[i-2][0]+dp[i-1][0]+dp[i-1][1]+dp[i-1][2] i表示列数啦
xxxx是怎么得到的呢。xx+L xx+ --
xxx xx xxx
dp[i][1]=dp[i-2][0]+dp[i-1][2]
xxx同理
xxxx
class Solution { public: const int mod = 1000000007; int dp[2000][3]; int numTilings(int N) { dp[1][0]=1,dp[0][0]=1; for(int i=2;i<=N;i++){ dp[i][0]=(dp[i-2][0]%mod+dp[i-1][0]%mod)%mod+(dp[i-1][1]%mod+dp[i-1][2]%mod)%mod; dp[i][1]=(dp[i-2][0]%mod+dp[i-1][2]%mod)%mod; dp[i][2]=(dp[i-2][0]%mod+dp[i-1][1]%mod)%mod; } return dp [0]%mod; } };
相关文章推荐
- Weekly Contest 73 leetcode 790. Domino and Tromino Tiling
- [Leetcode] 790. Domino and Tromino Tiling 解题报告
- [LeetCode] Domino and Tromino Tiling 多米诺和三格骨牌
- leetcode 790. Domino and Tromino Tiling
- 790. Domino and Tromino Tiling
- 790. Domino and Tromino Tiling
- 73th LeetCode Weekly Contest Escape The Ghosts
- LWC 73: 790. Domino and Tromino Tiling
- LeetCode 660 Remove 9 (LeetCode Weekly Contest 45)
- LeetCode Weekly Contest 45解题思路
- LeetCode Weekly Contest 6
- LeetCode Weekly Contest 25 之 537.Complex Number Multiplication
- LeetCode Weekly Contest 47解题思路
- LeetCode Weekly Contest 43【总结】
- leetcode weekly contest 61 ( 740. Delete and Earn )
- LeetCode Weekly Contest 43解题思路
- LeetCode Weekly Contest 26解题思路
- 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum
- LeetCode Weekly Contest 8
- LeetCode Weekly Contest 32解题思路