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. Gym - 100570B :ShortestPath Query(SPFA及其优化)

    题意:给定N点M边的有向图,每条边有距离和颜色,一条有效路径上不能有相邻的边颜色相同.现在给定起点S,多次讯问S到点X的最短有效距离. TLE思路:用二维状态dis(u,c)表示起点到u,最后一条边的 ...

  2. Excel文本获取拼音

    [说明] 版本:Excel 2010 文件后缀:.xls 有在.xlsb文件下使用未成功.建议使用.xls后缀. 1.调出“开发工具” 步骤:文件-->选项-->自定义功能区-->勾 ...

  3. 第k小和(搜索)

    Description [问题描述] 从n个数中选若干(至少1)个数求和,求所有方案中第k小的和(和相同但取法不同的视为不同方案).[输入格式]    第一行输入2个正整数n,k.    第二行输入这 ...

  4. 最长递增子序列(LIS)

    最长递增子序列(Longest Increasing Subsequence) ,我们简记为 LIS. 题:求一个一维数组arr[i]中的最长递增子序列的长度,如在序列1,-1,2,-3,4,-5,6 ...

  5. js---window对象的三种窗口

    ============================================================================ window对象的三种窗口.html < ...

  6. PHPstorm 常用快捷键操作

    1.ctrl+ N: 查找类 2.ctrl+ shift+ N: 全局搜索文件 ,优先文件名匹配的文件 3.ctrl + G: 定位行,跳转行 4.ctrl + F12: 显示当前页面类的所有方法 / ...

  7. JConsole远程监控配置

    首先,看本机(Windows)安装了JRE没 Win > CMD 打开命令窗口 如有安装,则会显示以下版本信息:若没有显示,就安装吧 C:\Users\Administrator>java ...

  8. koa2,koa1框架安装

    koa2版本安装: npm install koa@ -g hello2.js var Koa = require('koa'); var app = new Koa(); app.use(ctx = ...

  9. (转自精通Python设计模式)Python设计模式之创建型模式——2.建造者模式

    建造者模式将一个复杂对象的构造过程与其表现分离,这样,同一个构造过程可用于创建多个不同的表现. 我们来看个实际的例子,假设我们想要创建一个HMTL页面生成器,HTML页面的基本结构(构造组件)通常是一 ...

  10. 8、泛型程序设计与c++标准模板库2.5容器适配器

    容器适配器是用来扩展7中基本容器的,是修改和调整其他类接口的类.他们不提供存放数据的实际数据结构的实现方法,而且容器适配器也不支持迭代器. 1.标准栈容器 使用STL中的标准栈为程序员提供了一层附加的 ...