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

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 = ;
int dp[][];
int numTilings(int N) {
dp[][]=,dp[][]=;
for(int i=;i<=N;i++){
dp[i][]=(dp[i-][]%mod+dp[i-][]%mod)%mod+(dp[i-][]%mod+dp[i-][]%mod)%mod;
dp[i][]=(dp[i-][]%mod+dp[i-][]%mod)%mod;
dp[i][]=(dp[i-][]%mod+dp[i-][]%mod)%mod;
}
return dp[N][]%mod;
}
};

73th LeetCode Weekly Contest Domino and Tromino Tiling的更多相关文章

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

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

  2. 73th LeetCode Weekly Contest Custom Sort String

    S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...

  3. 73th LeetCode Weekly Contest Escape The Ghosts

    You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is(tar ...

  4. 73th LeetCode Weekly Contest Rotated Digits

    X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...

  5. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  6. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  7. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  8. Leetcode Weekly Contest 86

    Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...

  9. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

随机推荐

  1. 【LeetCode】048. Rotate Image

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  2. How to manage concurrency in Django models

    How to manage concurrency in Django models The days of desktop systems serving single users are long ...

  3. 最常见的5个导致 RAC 实例崩溃的问题

    适用于: OracleDatabase - Enterprise Edition - 版本11.2.0.1 和更高版本本文档所含信息适用于所有平台 用途 本文档的目的是总结可能导致 RAC 实例崩溃的 ...

  4. CentOS6.5中的vsftpd安装配置

    安装ftp 1.使用chkconfig 来查看是否装有vsftpd服务: 2.使用yum命令直接安装:yum -y install vsftpd 3.然后为它创建日志文件:touch /var/log ...

  5. bzoj4545

    lct+SAM bzoj4516+bzoj2555 这道题唯一的用处就是教会了我真正的广义SAM dfs时保留当前节点在后缀自动机中的位置,每个点接着父亲建 lct动态维护right集合大小,用lct ...

  6. window下git,TortoiseGit安装,以及和github托管项目

    下载地址:http://msysgit.github.io/,安装时最好是先装git,再安装TortoiseGit. 一.git安装 1.第一步 2.第二步 3.第三步 4.第四步 5.第五步 6.第 ...

  7. String/ StringBuilder/ StringBuffer

    1. 首先String不属于8种基本数据类型,String是一个对象. 因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. ne ...

  8. 网络编程之socket编程实例

    简单实例1 server.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include ...

  9. 网络编程之socket编程

    TCP/IP协议 网络层的“ip地址”可以唯一标识网络中的主机,而传输层的“协议+端口”可以唯一标识主机中的应用程序(进程).这样利用三元组(ip地址,协议,端口)就可以标识网络的进程了,网络中的进程 ...

  10. Centos6.8下yum安装python2.7

    下载 ius-release.rpm包 wget https://centos6.iuscommunity.org/ius-release.rpm 安装ius-release.rpm包 rpm -Uv ...