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< ...
随机推荐
- python工具之日志记录
''' 写日志类 日志存放目录为当前应用程序的目录下的log目录中 日志产生规则:每小时产生一个文件 write by :wujf 2017-02-24 ''' import sys import o ...
- 猩球StarBall ,一个方便约球的小程序
扫描小程序码直接进入小程序 猩球StarBall 是一款为热爱运动的人群提供便利的小程序. 开发技术为Java +Mysql 其中用到的技术框架为SpringBoot,Mybatis,Redis,Qu ...
- Android Studio V4 V7 包冲突的问题
最近被包冲突的问题搞奔溃了,特别是V4,V7 V4和V7包冲突的解决方式就是!版本要一致!! 比如我的一个项目中应用本来是这样引用包的 compile 'com.android.support:sup ...
- ubuntu下nginx+PHP-FPM安装配置
安装nginx apt-get install nginx 配置nginx 位置: /etc/nginx/nginx.conf ,其中包含了 include /etc/nginx/conf.d/*. ...
- 深入理解Java的整型类型:如何实现2+2=5?
先看下这段神奇的Java代码: public static void main(String[] args) throws Exception { doSomethingMagic(); System ...
- Netbeans Makefile: recipe for target 'XXX' failed 运行failed(退出值 -1073741511 找不到C/C++库文件,关键字
今天不知怎么的又出错了 吐血了 找不到NULL new等关键字了 看到知乎上有人和我一个问题,怎么办?很简单卸载了以前的cygwin和netbeans然后重装,我重装时没有把以前的cygwin ...
- SQLite -语法
SQLite -语法 SQLite是紧随其后的是独特的组称为语法的规则和指导方针.本教程为您提供了快速启动和SQLite的清单的所有基本SQLite语法. 大小写敏感性 注意重要的一点是,SQLite ...
- iOS端架构、基本组成与使用说明
一. app整体描述 app的描述:需求文档+接口文档+程序架构. 说明:新入手的开发人员必须拿到这三个说明文档才能整体了解app功能. 二.app架构描述 1.架构视图 2.分层结构说明 [1] a ...
- Linux environment variables (环境变量)
Environment variables are often used to store a list of paths of where to search for executables, li ...
- 初见Vue
一.What 官方定义:是一套用于构建用户界面的渐进式框架.这,what?不明觉厉,我反正现在还是不知道,在这之前,就只知道Vue.js是用来渲染数据的,其实它的核心库只关注视图层.不多说,用多了就知 ...