Circling Round Treasures(codeforces 375c)
题意:要求在一张网格图上走出一条闭合路径,不得将炸弹包围进去,使围出的总价值减去路径长度最大。
/*
类似于poj3182的做法,只不过出现了多个点,那么就用状态压缩的方法记录一个集合即可。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
char map[][],ch[];
int n,m,sx,sy,tx,ty,nx,ny,gx[],gy[],val[],w[],dp[][][],cnt=-,ans;
int dx[]={-,,,};
int dy[]={,,-,};
struct node{int x,y,k;};
bool ok(int j){
if(nx==gx[j]&&ny<gy[j]){
if(nx>tx)return true;
}
else if(tx==gx[j]&&ty<gy[j]){
if(tx>nx)return true;
}
return false;
}
void bfs(){
memset(dp,-,sizeof(dp));
queue<node> q;
node u;u.x=sx;u.y=sy;u.k=;q.push(u);dp[sx][sy][]=;
while(!q.empty()){
u=q.front();q.pop();nx=u.x;ny=u.y;int nk=u.k,tk;
if(nx==sx&&ny==sy)ans=max(ans,w[nk]-dp[nx][ny][nk]);
for(int i=;i<;i++){
tx=nx+dx[i];ty=ny+dy[i];tk=nk;
if(tx<||tx>n||ty<||ty>m||(map[tx][ty]!='.'&&map[tx][ty]!='S'))continue;
for(int j=;j<=cnt;j++)
if(ok(j))tk^=(<<j);
if(dp[tx][ty][tk]==-){
dp[tx][ty][tk]=dp[nx][ny][nk]+;
node v;v.x=tx;v.y=ty;v.k=tk;q.push(v);
}
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%s",ch);
for(int j=;j<=m;j++){
map[i][j]=ch[j-];
if(map[i][j]=='S')sx=i,sy=j;
if(map[i][j]>=''&&map[i][j]<=''){
int t=map[i][j]-'';++cnt;
gx[t]=i;gy[t]=j;
}
}
}
for(int i=;i<=cnt;i++)scanf("%d",&val[i]);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(map[i][j]=='B'){
++cnt;gx[cnt]=i;gy[cnt]=j;val[cnt]=-;
}
for(int i=;i<(<<cnt+);i++)
for(int j=;j<=cnt;j++)
if(i&(<<j))w[i]+=val[j];
bfs();
printf("%d",ans);
return ;
}
Circling Round Treasures(codeforces 375c)的更多相关文章
- Codeforces 375C - Circling Round Treasures(状压 dp+最短路转移)
题面传送门 注意到这题中宝藏 \(+\) 炸弹个数最多只有 \(8\) 个,故考虑状压,设 \(dp[x][y][S]\) 表示当前坐标为 \((x,y)\),有且仅有 \(S\) 当中的物品被包围在 ...
- Circling Round Treasures CodeForces - 375C
C. Circling Round Treasures time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #581(Div. 2)
Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...
- CF 375C Circling Round Treasures [DP(spfa) 状压 射线法]
C - Circling Round Treasures 题意: 在一个$n*m$的地图上,有一些障碍,还有a个宝箱和b个炸弹.你从(sx,sy)出发,走四连通的格子.你需要走一条闭合的路径,可以自交 ...
- (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)
(CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...
- Codeforces 375C Circling Round Treasures - 最短路 - 射线法 - 位运算
You have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure wit ...
- 【CodeForces - 1200C】Round Corridor (数论gcd)
Round Corridor Descriptions Amugae位于一个非常大的圆形走廊中.走廊由两个区域组成.内部区域等于nñ扇区,外部区域等于m米部门.在相同区域(内部或外部)的每对扇区之间 ...
- Educational Codeforces Round 29(6/7)
1.Quasi-palindrome 题意:问一个字符串(你可以添加前导‘0’或不添加)是否是回文串 思路:将给定的字符串的前缀‘0’和后缀‘0’都去掉,然后看其是否为回文串 #include< ...
随机推荐
- AJPFX关于JAVA多线程实现的三种方式
JAVA多线程实现方式主要有三种:继承Thread类.实现Runnable接口.使用ExecutorService.Callable.Future实现有返回结果的多线程.其中前两种方式线程执行完后都没 ...
- jQuery中面向对象思想实现盒子内容切换
这里主要是模拟小米官网中的首页的内容模块实现的主要动态效果 布局:采用了bootstrap框架进行布局,及其其中的字体图标 html: <!-- 内容 --> <div class= ...
- Linux PHP的运行模式
关系图 首先聊一下服务器,常见的web server类型有apache和nginx Apache工作模式 Apache的工作模式是Apache服务器在系统启动后,预先生成多个进程副本驻留在内存中,一旦 ...
- DLL入门浅析【转】
1.建立DLL动态库 动态链接库(DLL)是从C语言函数库和Pascal库单元的概念发展而来的.所有的C语言标准库函数都存放在某一函数库中.在链接应用程序的过程中,链接器从库文件中拷贝程序调用的函数 ...
- sql server 2000备份还原数据库
转载请注明出处:http://blog.csdn.net/neochan1108/article/details/79248017 备份: -- Create the backup device fo ...
- 【Win32汇编】编译环境配置
开始学习[Win32汇编],编译过程较为繁琐,做个记录. 使用 MASM32 提供的 ml.exe 和 link.exe,以及 VS2013 中的 nmake.exe 和资源编辑器. ml.exe: ...
- CATransaction 知识
CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务. 区分隐式动画和隐式事务:隐式动画通过隐式事务实现动画 . 区分显式动画和显式事务:显式动画有多种 ...
- Linux OpenGL 实践篇-10-framebuffer
在之前的实践中我们都是在当前的窗口中渲染,即使用的缓存都是由glutCreateWindow时创建的缓存,我们可称之为默认缓存.它是唯一一个可以被图形服务器的显示系统识别的帧缓存,我们在屏幕上看到的只 ...
- (转)Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案一
http://blog.csdn.net/yerenyuan_pku/article/details/52888808 前面我们已经集成了Spring4.2.5+Hibernate4.3.11这两个框 ...
- Android(java)学习笔记181:多媒体之图片画画板案例
1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...