当前位置:网站首页>LeetCode 2320. 统计放置房子的方式数
LeetCode 2320. 统计放置房子的方式数
2022-07-02 11:26:00 【HumbleFool】
const int mod = 1e9 + 7;
class Solution {
public:
int countHousePlacements(int n) {
vector<vector<int>> f(n + 1, vector<int>(2, 0));
// 状态机模型:f[i][1] 代表前i个且以0结尾或以1结尾
f[1][0] = f[1][1] = 1;
for(int i = 2 ; i <= n; i ++)
{
f[i][1] = f[i - 1][0] % mod;
f[i][0] = (f[i - 1][0] + f[i - 1][1]) % mod;
}
long long t = 0LL + f[n][1] + f[n][0];
return t * t % mod;
}
};
边栏推荐
- taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
- A white hole formed by antineutrons produced by particle accelerators
- Fabric.js 橡皮擦的用法(包含恢复功能)
- 什么是 eRDMA?丨科普漫画图解
- Fabric.js 元素被选中时保持原有层级
- buuctf-pwn write-ups (7)
- Advanced C language (realize simple address book)
- Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
- Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
- Fabric.js 动态设置字号大小
猜你喜欢
【apipost】使用教程
Daily learning 2
obsidian安装第三方插件——无法加载插件
Socket and socket address
Xilinx Vivado set *.svh as SystemVerilog Header
Fabric. Usage of JS eraser (including recovery function)
Daily learning 3
taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
<口算練習機 方案開發原理圖>口算練習機/口算寶/兒童數學寶/兒童計算器 LCD液晶顯示驅動IC-VK1621B,提供技術支持
taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口
随机推荐
Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
Yyds dry goods inventory software encryption lock function
< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621
Yolov3 & yolov5 output result description
Stm32-dac Experiment & high frequency DAC output test
Factal: Unsafe repository is owned by someone else Solution
Tmall product details interface (APP, H5 end)
PHP linked list creation and traversal
Makefile 分隔文件名与后缀
fatal: unsafe repository is owned by someone else 的解决方法
Xilinx Vivado set *.svh as SystemVerilog Header
Quick analysis: easy to share the Internet
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
Socket and socket address
【apipost】使用教程
The use of TestNG, the testing framework (II): the use of TestNG XML
Basic knowledge of QT original code
Pychart connects to the remote server
taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing