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 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的更多相关文章
- 【LeetCode】790. Domino and Tromino Tiling 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/domino-a ...
- 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 ...
- 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 ...
- 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 ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
- LeetCode Weekly Contest 23
LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...
- Leetcode Weekly Contest 86
Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...
- LeetCode Weekly Contest
链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...
随机推荐
- ACM学习历程—POJ3565 Ants(最佳匹配KM算法)
Young naturalist Bill studies ants in school. His ants feed on plant-louses that live on apple trees ...
- 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView
目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...
- spring容器扩展功能之一:spring加载ApplicationContext.xml的四种方式
容器加载Bean的常见两个类ApplicationContext和BeanFactory, 一.首先,看看spring中加载配置在xml中的Bean对象到容器 spring 中加载xml配置文件的方式 ...
- js之翻牌游戏中的一个深刻感悟
先“上菜”: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- 杂项:Webpack
ylbtech-杂项:Webpack 本质上,webpack 是一个现代 JavaScript 应用程序的静态模块打包器(module bundler).当 webpack 处理应用程序时,它会递归地 ...
- 关于 vs 2012 键盘无法输入的问题
使用vs2012 新建了一个类文件之后,vs2012的编辑界面突然出现奇怪的问题,键盘无法输入! 最后调查的结果是由于resharper插件导致的. 可以将插件禁用然后启用. 也可以删除resharp ...
- pip 在windows下如何升级
建议:由于是pip的国外的,在更新之前先开启vpn,这样更新会顺畅些. 官方网页要求在 cmd中输入以下命令进行 pip的 更新: python -m pip install -U pip 更新成功后 ...
- 8、泛型程序设计与c++标准模板库1、泛型程序设计的概念和术语
有效地利用已有的成果,将经典的.优秀的算法标准化.模块化,从而提高软件的生产率,是软件产业化的需求,为了实现这一需求,不仅需要面向对象设计思想,而且需要泛型程序设计思想. c++语言提供的标准模板库( ...
- [亂數] <細說> C/C++ 亂數基本使用與常見問題
陸陸續續寫了 EA 一.二年,以前亂數引導文回頭看時才發現,怎麼有這麼多細節的錯誤.沒系統. 這篇文章主要引導初學者使用亂數,同時附上常被翻出來討論的議題,C/C++適用,唯以 C 語言撰之. 也由 ...
- C习题练习
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h> //比较俩个数的大小 //int max(int a, int b) {// int t ...