当前位置:网站首页>State compression DP acwing 291 Mondrian's dream
State compression DP acwing 291 Mondrian's dream
2022-07-03 09:06:00 【T_ Y_ F666】
State compression DP AcWing 291. Mondrian's dream
Original link
Algorithm tags
Dynamic programming State compression DP
Ideas
Specific ideas
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 12, M = 1 << N;
int f[N][M], st[M];
vector<int> sta[M];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
while(n=read(), m=read(), n||m){
// Preprocessing : Judge whether the status of the consolidated column is legal
// If a row of the merged column is 1 It means horizontal , yes 0 Indicates vertical placement
// If there is no continuous odd number of merged columns 0, It is the state of Taiwan France
rep(i, 0, 1<<n){
// cnt For how many consecutive 0
int cnt=0;
st[i]=true;
rep(j, 0, n){
if(i>>j&1){// If it is 1
if(cnt&1){// If it's continuous 0 The number of is odd
st[i]=false;// Record i illegal
cnt=0;
}
}
else{// If it is 1, Record 0 The number of
cnt++;
}
}
// Handle high order 0 The number of With 4 For example 0100 It is also an illegal number
if(cnt&1){
st[i]=false;
}
}
// State calculation
memset(f, 0, sizeof f);
// The first 0 It is a legal scheme that columns are not placed horizontally
f[0][0]=1;
rep(i, 1, m+1){// Stage : Enumerating columns
rep(j, 0, 1<<n){// state : Enumerate the i The state of the column
rep(k, 0, 1<<n){// state : Enumerate the 11 The state of the column
// j & k == 0 Express i Column sum i - 1 List the same row and poke it out at the same time
// st[j | k] == 1 Express stay i Column status j, i - 1 Column status k Is legal .
// The two columns are compatible : There is no overlap 1, There are no consecutive odd days
if((j&k)==0&&st[j|k]){
f[i][j]+=f[i-1][k];
}
}
}
}
// The first m The columns are not placed horizontally , That is the answer.
printf("%lld\n", f[m][0]);
}
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- 樹形DP AcWing 285. 沒有上司的舞會
- PHP uses foreach to get a value in a two-dimensional associative array (with instances)
- Analysis of Alibaba canal principle
- Methods of checking ports according to processes and checking processes according to ports
- 网络安全必会的基础知识
- [set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
- 【点云处理之论文狂读经典版14】—— Dynamic Graph CNN for Learning on Point Clouds
- DOM 渲染系统(render mount patch)响应式系统
- On the difference and connection between find and select in TP5 framework
- 求组合数 AcWing 885. 求组合数 I
猜你喜欢
剑指 Offer II 091. 粉刷房子
excel一小时不如JNPF表单3分钟,这样做报表,领导都得点赞!
I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
【点云处理之论文狂读经典版14】—— Dynamic Graph CNN for Learning on Point Clouds
Sword finger offer II 029 Sorted circular linked list
Es8 async and await learning notes
【点云处理之论文狂读经典版8】—— O-CNN: Octree-based Convolutional Neural Networks for 3D Shape Analysis
Log4j2 vulnerability recurrence and analysis
What is an excellent fast development framework like?
Facial expression recognition based on pytorch convolution -- graduation project
随机推荐
Binary tree sorting (C language, int type)
How to place the parameters of the controller in the view after encountering the input textarea tag in the TP framework
Life cycle of Servlet
LeetCode 75. 颜色分类
Redux - learning notes
Log4j2 vulnerability recurrence and analysis
PHP uses foreach to get a value in a two-dimensional associative array (with instances)
浅谈企业信息化建设
一个优秀速开发框架是什么样的?
Character pyramid
Really explain the five data structures of redis
【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition
On a un nom en commun, maître XX.
Alibaba canal actual combat
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
精彩回顾|I/O Extended 2022 活动干货分享
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
LeetCode 715. Range module
Methods of using arrays as function parameters in shell
LeetCode 324. 摆动排序 II