当前位置:网站首页>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;
}边栏推荐
- Irregular clipping of NC data with CDO
- 追踪伦敦银实时行情的方法有哪些?
- 【commons-lang3专题】004- NumberUtils 专题
- 保护性拷贝&无状态
- Five interesting magic commands in jupyter notebook
- B+ tree~
- 深度学习 | MATLAB实现TCN时间卷积神经网络spatialDropoutLayer参数描述
- Several methods of multi-threaded sequential operation can be asked casually in the interview
- 【树莓派】widows电脑如何与树莓派连接
- iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器
猜你喜欢

NFT 项目的 7 种市场营销策略
![[target detection] Introduction to yolor theory + practical test visdrone data set](/img/cd/3cb13d6d79cd207c6d637af7756ffc.png)
[target detection] Introduction to yolor theory + practical test visdrone data set

Method of converting inline elements to block elements

Educational Codeforces Round 132 (Rated for Div. 2)【A~C】

【AD学习】本次海上航行器大赛画pcb图的历程

面试突击69:TCP 可靠吗?为什么?

Some considerations about ThreadPool
![“index [hotel/jXLK5MTYTU-jO9WzJNob4w] already exists“](/img/f2/37a1e65eb1104d72128f96fc5d9c85.png)
“index [hotel/jXLK5MTYTU-jO9WzJNob4w] already exists“
![[unity] configure unity edit C as vscode](/img/f6/5675a96115fb97737c8b36a3fcc6ed.png)
[unity] configure unity edit C as vscode

How to explain JS' bind simulation implementation to your girlfriend
随机推荐
Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
自制 | 纯手工自制一个16位RISC架构CPU
Return the member function of *this
机器学习 | MATLAB实现RBF径向基神经网络newrbe参数设定
“index [hotel/jXLK5MTYTU-jO9WzJNob4w] already exists“
In the second round, 1000 okaleido tiger were sold out in one hour after logging in to binance NFT again
What opportunities does the London gold real-time market bring?
B站“崩溃”始末 2021.07.13 我们是这样崩的(转载)
QT static compiler (MinGW compilation)
【刷题笔记】从链表中删去总和值为零的连续节点
Wechat campus bathroom reservation applet graduation design finished product (5) assignment
小程序毕设作品之微信校园浴室预约小程序毕业设计成品(5)任务书
时序预测 | MATLAB实现TCN时间卷积神经网络的时间序列预测
Daniel guild Games: summary and future outlook of this year
MATLAB02:结构化编程和函数定义「建议收藏」
[notes for question brushing] specified interval reversal in the linked list
redis版本怎么查看(查看redis进程)
Seven marketing strategies of NFT project
Definition of double linked list~
浅谈一下跨端技术方案