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总结List的三个子类的特点
ArrayList: 底层数据结构是数组,查询快,增删慢. 线程不安全,效率高. ...
- [转]FaceBook ATC 弱网测试工具环境搭建
工具简介 ATC是FaceBook开源的移动网络测试工具Augmented Traffic Control(ATC),能够方便的让我们模拟各种网络环境进行测试. ATC有两个最吸引人的特点: 在手机上 ...
- How to proxy a web site by apache2 in Ubuntu
Install apache2 To execute the install command in terminal: sudo apt-get install apache2 Then, we ca ...
- 【HEVC帧间预测论文】P1.3 Fast Inter-Frame Prediction Algorithm of HEVC Based on Graphic Information
基于图形信息的HEVC帧间预测快速算法/Fast Inter-Frame Prediction Algorithm of HEVC Based on Graphic Information <H ...
- AngularJS日期格式化
本地化日期格式化:({{ today | date:'medium' }}) Mar 28, 2016 6:42:25 PM({{ today | date:'short' }}) 3/28 ...
- 使用Recast.AI创建具有人工智能的聊天机器人
很多SAP顾问朋友们对于人工智能/机器学习这个话题非常感兴趣,也在不断思考如何将这种新技术和SAP传统产品相结合.Jerry之前的微信公众号文章C4C和微信集成系列教程曾经介绍了Partner如何利用 ...
- 命令终端执行python
windows进入cmd 1.进入cmd窗口,找到存放py文件的地址(如E:\learn_mock) 2.退出python,输入exit() linux下一样
- python关于入参中,传入的是指针还是引用
偶然看到别人的代码,发现有的会传入参数之后,做一次copy,试验一下,关于入参中,传入的是指针还是引用先说自己的结论:1.如果传入的是简单的类型,那么传入应该是引用的数值,2.假如传入的是df这种类型 ...
- 初探node.js
一.定义及优势 定义:Node.js是一个基于 Chrome V8 引擎 的 JavaScript 运行时,它以事件驱动为基础实现了非阻塞模型. 优势:由于Web场景下的大多数任务(静态资源读取.数据 ...
- WebGL 绘制Line的bug(二)
上一篇文章简单介绍了WebGL绘制Line的bug,不少朋友给我发了私信,看来这个问题大家都遇上过哈.今天这篇文章会讲述解决这个问题的work around. 基本思路 上一篇文章结尾简单提了下解决的 ...