当前位置:网站首页>State compression DP Mondrian's dream
State compression DP Mondrian's dream
2022-07-29 01:01:00 【znyee07】
Topic link :
291. Mondrian's dream - AcWing Question bank
https://www.acwing.com/problem/content/description/293/
f[i][j] Express : front i - 1 The columns are in place , And from the i - 1 Lie Xiangdi i The status of leyanshen is j
The core :
The number of small square schemes placed Equivalent to The number of small square schemes placed horizontally
How to judge whether the current scheme is legal ?
Traverse each column ,i The number of schemes in the column is only equal to i-1 List related
1. j&k==0, i-2 The column extends to i-1 The little squares of and i-1 Small square for column placement No repetition .
2. Each column , All continuous empty squares must be even
#include<bits/stdc++.h>
using namespace std;
const int N = 10, M = 1 << N;
//M Each bit of binary stores a bit state
int st[M];
// Store the legal placement status on each column
long long f[N][M];
//f[i][j] Express : front i-1 The columns are in place , And from the i-1 Lie Xiangdi i The status of leyanshen is j
// & Only two are 1 Only then 1
// | There is one 1 Namely 1
// ^ The difference between the two numbers is 1
int main()
{
int n, m; cin >> n >> m;
for(int i = 0; i < 1 << n; i++)// Enumerate which of the placeholder states of each column is legal
{ //i * 2 Of n Power ,i Of 2 Hexadecimal shift left n position ,
// altogether n Column , There are two cases in each grid , by 0( Don't put ), by 1( discharge )
int cnt = 0;
// Record in a column 0 The number of
st[i] = true;
for(int j = 0; j < n; j++)// Enumerate every bit from low to high
if(i >> j & 1)// If the bit is 1
{
if(cnt & 1)//cnt It is true when it is an odd number
//cnt & 1 It's true , It means continuous 0 It's odd
st[i] = false;
cnt = 0;
}
else cnt ++;
// This bit is 0, 0 The number of ++
if(cnt & 1) st[i] = false;
// At the end Judge the front 0 The number of
}
f[0][0] = 1;
// non-existent -1 Column , So the first 0 Xing di 0 Column There will be no extended horizontal small squares
for(int i = 1; i <= m; i++)// Traverse each column
{
for(int j = 0; j < 1 << n; j++)// Traverse i List each state
{
for(int k = 0; k < 1 << n; k++)// Traverse i - 1 List each state
if((j & k) == 0 && (st[j | k]))
// Two transfer conditions :
//i Column sum i - 1 List the same row and poke it out at the same time ;
// The status of this column j And the State mentioned above k Seek or ,
// Get whether the above column is in odd empty row status , Odd blank lines do not transfer .
//st[j | k] == 1 Express stay i Column status j, i - 1 Column status k Is legal .
f[i][j] += f[i - 1][k];
// State shift
}
}
cout<< f[m][0];
// front m - 1 The column has been placed , And there's no m - 1 Line up m Column extension
return 0;
}边栏推荐
- 电子招标初学者指南
- [target detection] Introduction to yolor theory + practical test visdrone data set
- Selenium docking agent and selenium wire access developer tool network
- Seven marketing strategies of NFT project
- MATLAB02:结构化编程和函数定义「建议收藏」
- 管理区解耦架构见过吗?能帮客户搞定大难题的
- DRF - deserialization of serializer, fields and parameters, local and global hooks, use of modelserializer
- 小程序毕设作品之微信校园浴室预约小程序毕业设计成品(8)毕业设计论文模板
- Charles -- teach you how to use the packet capturing tool from 0-1
- 🧐 table1 | 一秒搞定你的三线表
猜你喜欢

Some considerations about ThreadPool

Five interesting magic commands in jupyter notebook

What are the methods to track the real-time market of London Silver?

Cookie和Session

追踪伦敦银实时行情的方法有哪些?

小程序毕设作品之微信校园浴室预约小程序毕业设计成品(7)中期检查报告

自制 | 纯手工自制一个16位RISC架构CPU

Method of converting inline elements to block elements
![[web development] basic knowledge of flask framework](/img/79/5ece84552c82e98f5e15fac1ee3335.png)
[web development] basic knowledge of flask framework

Tips for API interface optimization
随机推荐
深度学习 | MATLAB实现TCN时间卷积神经网络spatialDropoutLayer参数描述
Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
靠云业务独撑收入增长大梁,微软仍然被高估?
如何给女友讲明白JS的bind模拟实现
【无标题】
追踪伦敦银实时行情的方法
【刷题笔记】二进制链表转整数
NFT 项目的 7 种市场营销策略
iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器
Interview shock 69: is TCP reliable? Why?
小程序毕设作品之微信校园浴室预约小程序毕业设计成品(5)任务书
AQS原理
保护性拷贝&无状态
[raspberry pie] how does the windows computer connect with raspberry pie
[Commons lang3 topic] 005- objectutils topic
DRF - paging, JWT introduction and principle, JWT quick use, JWT source code analysis, JWT custom return format, custom user issued token, custom token authentication class
B+ tree~
Selenium docking agent and selenium wire access developer tool network
The method of tracking the real-time market of London Silver
【commons-lang3专题】001-StringUtils 专题