当前位置:网站首页>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;
}边栏推荐
- Kwai focuses on regulating the number maintenance behavior in the ways of handling and manuscript washing, and how to purify the content ecology on the we media platform
- mysql时间按小时格式化_mysql时间格式化,按时间段查询的MySQL语句[通俗易懂]
- QT静态编译程序(Mingw编译)
- B- 树 ~
- mysql存储过程 实现创建一张表(复制原表的结构新建的表)
- [Commons lang3 topic] 001 stringutils topic
- Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
- [Yugong series] go teaching course in July 2022, an array of 020 go containers
- NFT 项目的 7 种市场营销策略
- Charles -- teach you how to use the packet capturing tool from 0-1
猜你喜欢

Data warehouse construction - ads floor

Inftnews | yuanuniverse shopping experience will become a powerful tool to attract consumers

Techo Hub 福州站干货来袭|与开发者共话工业智能新技术

Data warehouse construction - DWT floor

【无标题】

云函数实现网站自动化签到配置详解【Web函数/Nodejs/cookie】

关于ThreadPool的一些注意事项
![[raspberry pie] how does the windows computer connect with raspberry pie](/img/d6/42685bbc4e4af757867442b63ce9c8.png)
[raspberry pie] how does the windows computer connect with raspberry pie

NFT 项目的 7 种市场营销策略

Jupyter notebook中5个有趣的魔法命令
随机推荐
DRF -- authentication, authority, frequency source code analysis, global exception handling, automatic generation of interface documents, RBAC introduction
【刷题笔记】二进制链表转整数
对接支付宝支付
Have you seen the management area decoupling architecture? Can help customers solve big problems
JWT token related configuration (global configuration identity authentication rewrites authenticate method)
[Yugong series] go teaching course in July 2022, an array of 020 go containers
进程和线程知识点总结 2
[notes for question brushing] specified interval reversal in the linked list
How to explain JS' bind simulation implementation to your girlfriend
第二轮1000个Okaleido Tiger,再次登录Binance NFT 1小时售罄
iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器
[target detection] Introduction to yolor theory + practical test visdrone data set
Techo Hub 福州站干货来袭|与开发者共话工业智能新技术
异步模式之工作线程
Interview shock 69: is TCP reliable? Why?
What opportunities does the London gold real-time market bring?
Educational Codeforces Round 132 (Rated for Div. 2)【A~C】
ActiveMQ基本详解
时间序列数据的预处理方法总结
【commons-lang3专题】002- RandomUtils 专题