【状压+状态转移】A Famous Airport Managere
https://www.bnuoj.com/v3/problem_show.php?pid=25653
【题意】
- 给定一个3*3的九宫格,模拟一个停机坪。第一个格子一定是'*',代表take off area,其他的格子可能是'*','B','G'中的一种,'*'代表空地,'B','G'代表蓝色和绿色的飞机。
- 每次操作都是一个飞机移动到take off area并起飞,在这个过程中其他飞机不能动。
- 问有多少种飞机起飞的不同序列,同一种颜色的飞机是一模一样的。
【思路】
- 这个停机坪最多有3^8=6561中不同的状态,可以考虑用三进制状压。
- 状态之间可以转移。比如:
可以由
转移来,也就是当前的出队序列就是B+pre的出队序列。
可以由
转移来,也就是当前的出队序列就是G+pre的出队序列。
- 这个出队序列也可以状压,为了表示方便,我们把当前的出队序列表示为pre的出队序列后面接上B或G,这样就可以用[pre]*3+1或[pre]*3+2表示当前状态。
- 使用set可以自动去重,去掉重复的状态。
【Accepted】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
const int maxn=;
const int inf=0x3f3f3f3f;
char s[][];
int a[];
int dig[];
set<int> dp[maxn];
set<int>:: iterator it;
bool v[][];
int dir[][]={{,},{,},{,-},{-,}};
void init()
{
dig[]=;
for(int i=;i<=;i++)
{
dig[i]=dig[i-]*;
}
} void BFS()
{
queue<pair<int,int> >Q;
memset(v,false,sizeof(v));
Q.push(make_pair(,));
v[][]=true;
while(!Q.empty())
{
int x=Q.front().first;
int y=Q.front().second;
Q.pop();
// cout<<x<<" "<<y<<endl;
for(int i=;i<;i++)
{
int xx=x+dir[i][];
int yy=y+dir[i][];
if(v[xx][yy])
{
continue;
}
if(xx<||x>=||y<||y>=)
{
continue;
}
v[xx][yy]=true;
if(s[xx][yy]=='*')
{
Q.push(make_pair(xx,yy));
}
}
}
} void DP()
{
dp[].insert();
for(int i=;i<dig[];i++)
{
int now=i;
for(int j=;j<;j++)
{
a[-j]=now%;
now/=;
}
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
if(a[j*+k]==)
{
s[j][k]='*';
}
else if(a[j*+k]==)
{
s[j][k]='B';
}
else
{
s[j][k]='G';
}
}
}
BFS();
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
if(v[j][k]&&s[j][k]=='B')
{
int pre=i-*dig[-*j-k];
for(it=dp[pre].begin();it!=dp[pre].end();it++)
{
dp[i].insert(*(it)*+);
}
}
else if(v[j][k]&&s[j][k]=='G')
{
int pre=i-*dig[-*j-k];
for(it=dp[pre].begin();it!=dp[pre].end();it++)
{
dp[i].insert(*(it)*+);
}
}
}
}
}
}
int main()
{
init();
DP();
int cas=;
while(~scanf("%s%s%s",s[],s[],s[]))
{
for(int i=;i<;i++)
{
for(int k=;k<;k++)
{
if(s[i][k]=='*')
{
a[*i+k]=;
}
else if(s[i][k]=='B')
{
a[*i+k]=;
}
else
{
a[*i+k]=;
}
}
}
int now=;
for(int i=;i<;i++)
{
now+=a[i]*dig[-i];
}
printf("Case %d: ",++cas);
cout<<dp[now].size()<<endl;
} return ;
}
【状压+状态转移】A Famous Airport Managere的更多相关文章
- 【noip2016提高组day2T3】【愤怒的小鸟】状压dp转移时的集合包含
(上不了p站我要死了,图来自百度,侵权度娘背锅) 调死我了... 标题就说明了,死在了集合包含上.因为这道题与其他的状压题不同,其他的题基本上都是要求集合不重合,而这道题完全是可以的. 废话不多说,先 ...
- bzoj1054: [HAOI2008]移动玩具 状压+爆搜即可
题意:在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移动次数将初的玩具状态 ...
- BZOJ1076 [SCOI2008]奖励关 【状压dp + 数学期望】
1076: [SCOI2008]奖励关 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 3074 Solved: 1599 [Submit][Sta ...
- CF580D Kefa and Dishes 状压dp
When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. Th ...
- codevs1358棋盘游戏(状压dp)
1358 棋盘游戏 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 大师 Master 题目描述 Description 这个游戏在一个有10*10个格子的棋盘上进行,初 ...
- Codeforces.662C.Binary Table(状压 FWT)
题目链接 \(Description\) 给定一个\(n\times m\)的\(01\)矩阵,你可以选择一些行和一些列并将其中所有的\(01\)反转.求操作后最少剩下多少个\(1\). \(n\le ...
- P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 状压dp
这个状压dp其实很明显,n < 18写在前面了当然是状压.状态其实也很好想,但是有点问题,就是如何判断空间是否够大. 再单开一个g数组,存剩余空间就行了. 题干: 题目描述 A little k ...
- 洛谷 P3112 后卫马克 —— 状压DP
题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...
- ARC 093 F Dark Horse 容斥 状压dp 组合计数
LINK:Dark Horse 首先考虑1所在位置. 假设1所在位置在1号点 对于此时剩下的其他点的方案来说. 把1移到另外一个点 对于刚才的所有方案来说 相对位置不变是另外的方案. 可以得到 1在任 ...
随机推荐
- ssrs 2016, mobile report error: The report may be misconfigured, the data may not be available, or the server version may be unsupported.
使用多账户配置ssrs mobile report 权限后,使用客户端显示: 使用web 查阅,显示: 遇到这种情况,可能是由于,report引用了 数据集文件夹中的数据集,请记得把数据集文件夹上为该 ...
- ASP.NET CORE 使用 EF CORE访问数据库
asp.net core通过ef core来访问数据库,这里用的是代码优先,通过迁移来同步数据库与模型. 环境:vs2017,win10,asp.net core 2.1 一.从建立asp.net c ...
- maven 工程导入jar包
Maven项目引入jar包的方法,希望能帮助有需要的朋友们 法一.手动导入:项目右键—>Build Path—>Configure Build Path—>选中Libraries—& ...
- ASP.NET URLRewriter重写
URLRewriter重写是微软官方出的第三方重写插件 下载地址:http://download.csdn.net/detail/ysn1314/5421587 下载后在项目中添加引用,然后再配置文件 ...
- Node.js——防盗链
防盗链可以通过判断请求头中携带的referrer是否属于本域名
- Functor、Applicative 和 Monad x
首先,我们来看一下 Functor typeclass 的定义: 1 2 class Functor f where fmap :: (a -> b) -> f a -> f b F ...
- Hibernate的入门使用
数据在各个层次之间流转,在流转过程中会发生数据类型转换等一系列的交互问题.java与html的交互解决方案是struts2提供的OGNL(对象导航图语言),而java与数据库之间的技术解决方案是ORM ...
- AttributeError: 'tuple' object has no attribute 'extend'
出错demo In [5]: a.extend([4,5]) --------------------------------------------------------------------- ...
- android studio 调试安装
最新的手机无法debug安装调试. vivo x21 oppo r11等 解决办法: 1,关闭instant run Android Studio->Preferences->Build ...
- 2. 区分散列的 undef 值, 和手动赋值 0 不一样。1. 使用exists函数,散列中有这个键(必须是keys %hash 有这结果),则返回真值,
2. 123 my %vertical_alignment; 124 $vertical_alignment{"subscripting"} = 0; 125 unle ...