当前位置:网站首页>Mondriaans‘s Dream(状态压缩DP)
Mondriaans‘s Dream(状态压缩DP)
2022-07-26 16:53:00 【Li-Bolin】
思路:把行号作为dp的阶段,为了便于描述每一行的状态,我们可以用一个M位二进制数来表示这一行的状态。
如何转移:当满足一下两个条件时:
01-第i-1行的竖着的小方块(这一行状态表示为j)与第i行的竖着的小方块(这一行状态表示为k)不重叠,即 j & k == 0;
02-每一行的连续的0必须是偶数个,方便防止横着的小方块
#include <iostream>
using namespace std;
typedef long long ll;
ll f[12][1 << 11];
int n, m;
bool ck[1 << 11];
int lowbit(int x)
{
return x & -x;
}
int main()
{
while(cin >> n >> m && n)
{
// 预处理每行连续的0为偶数的情况,若存在奇数则标记为false
for(int i = 0; i < 1 << m; i++)
{
int cnt = 0, f = 0, t = i; // cnt 记录上一段连续0的数量
for(int j = 0; j < m; j++)
{
if(t >> j & 1)
{
if(cnt % 2 == 1)
{
f = 1;
break;
}
else
cnt = 0;
}
else cnt++;
}
if(f == 0 && cnt % 2 == 0) ck[i] = true;
else ck[i] = false;
}
// cout << ck[2] << endl;
f[0][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < 1 << m; j++)
{
f[i][j] = 0;
for(int k = 0; k < 1 << m; k++)
{
if((j & k) == 0 && ck[j | k])
f[i][j] += f[i - 1][k];
}
}
}
cout << f[n][0] << endl;
}
return 0;
}边栏推荐
- Tensor operation in pytoch
- 2019 popularization group summary
- 【虚拟机数据恢复】意外断电导致XenServer虚拟机不可用,虚拟磁盘文件丢失的数据恢复案例
- On the growth of data technicians
- In depth exploration of ribbon load balancing
- Spark统一内存划分
- Application of machine vision in service robot
- 使用 Dired 快速移动文件
- 解决哈希冲突的几种方式
- Review the past and know the new MySQL isolation level
猜你喜欢

【OpenCV 例程 300篇】240. OpenCV 中的 Shi-Tomas 角点检测

Establishment of Eureka registration center Eureka server

Advantages of time series database and traditional database

We were tossed all night by a Kong performance bug

Review the past and know the new MySQL isolation level

机器学习-什么是机器学习、监督学习和无监督学习

Pass-19,20

(24)Blender源码分析之顶层菜单显示代码分析
![[virtual machine data recovery] data recovery cases in which XenServer virtual machine is unavailable due to accidental power failure and virtual disk files are lost](/img/99/e5404a09ec7f52a7c5d7be23e43e85.jpg)
[virtual machine data recovery] data recovery cases in which XenServer virtual machine is unavailable due to accidental power failure and virtual disk files are lost

来吧开发者!不只为了 20 万奖金,试试用最好的“积木”来一场头脑风暴吧!...
随机推荐
如何快速使用 ELisp 进行插件编写
How does the data link layer transmit data
Good afternoon, everyone. Please ask a question: how to start a job submitted in SQL from the savepoint? Problem Description: using SQL in Cl
Concepts and differences of DQL, DML, DDL and DCL
Tensor operation in pytoch
Heavy announcement! Icml2022 Awards: 15 outstanding papers, selected by Fudan University, Xiamen University and Shanghai Jiaotong University
(24) the top menu of blender source code analysis shows code analysis
Data preprocessing of machine learning
敏捷开发与DevOps的对比
Shrimp Shope get commodity details according to ID API return value description
Is it really safe and reliable to exempt five in case of opening an account in a stock company
Implementing dropout with mxnet from zero sum
kudu设计-tablet
Cloud rendering volume cloud [theoretical basis and implementation scheme]
点击劫持攻击
跨站脚本攻击(XSS)
ASEMI整流桥KBPC2510,KBPC2510参数,KBPC2510规格书
SQL injection (mind map)
硬件开发与市场产业
Comparison between agile development and Devops