题意:要求在一张网格图上走出一条闭合路径,不得将炸弹包围进去,使围出的总价值减去路径长度最大。

/*
类似于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)的更多相关文章

  1. Codeforces 375C - Circling Round Treasures(状压 dp+最短路转移)

    题面传送门 注意到这题中宝藏 \(+\) 炸弹个数最多只有 \(8\) 个,故考虑状压,设 \(dp[x][y][S]\) 表示当前坐标为 \((x,y)\),有且仅有 \(S\) 当中的物品被包围在 ...

  2. Circling Round Treasures CodeForces - 375C

    C. Circling Round Treasures time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. Codeforces Round #581(Div. 2)

    Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...

  4. CF 375C Circling Round Treasures [DP(spfa) 状压 射线法]

    C - Circling Round Treasures 题意: 在一个$n*m$的地图上,有一些障碍,还有a个宝箱和b个炸弹.你从(sx,sy)出发,走四连通的格子.你需要走一条闭合的路径,可以自交 ...

  5. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  6. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  7. 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 ...

  8. 【CodeForces - 1200C】Round Corridor (数论gcd)

    Round Corridor  Descriptions Amugae位于一个非常大的圆形走廊中.走廊由两个区域组成.内部区域等于nñ扇区,外部区域等于m米部门.在相同区域(内部或外部)的每对扇区之间 ...

  9. Educational Codeforces Round 29(6/7)

    1.Quasi-palindrome 题意:问一个字符串(你可以添加前导‘0’或不添加)是否是回文串 思路:将给定的字符串的前缀‘0’和后缀‘0’都去掉,然后看其是否为回文串 #include< ...

随机推荐

  1. phpstorm设置代码块快捷方式

    File -> Settings -> Live Templates

  2. c# 移除数组为空元素

    通过字符串分割取得的数组中,有的时候可能需要处理除掉数组元素值为空的情况,所以可以按照如下代码完成: string rs="";//需要分割的字符串 char[] chspilt= ...

  3. codevs 1979 第K个数

     时间限制: 1 s  空间限制: 1000 KB  题目等级 : 黄金 Gold 题目描述 Description 给定一个长度为N(0<n<=10000)的序列,保证每一个序列中的数字 ...

  4. elasticsearch插入索引文档 对数字字符串的处理

    对于字符串在搜索匹配的时候,字符串是数字的话需要匹配的是精准匹配,如果是部分匹配字符串的话,需要进行处理,把数字型字符串作为一个字符中的数组表示插入之后显示如下: 如果插入之后显示如画线部分的话,则表 ...

  5. Java三大特性之继承

    二.类的继承 1. 概念:从已有的类中派生出新的类,新的类能吸收已有类的属性和行为,并能扩展新的能力. 2. 一个不由任何类派生出来的类称为基类,一个派生类最近的上层类称为该类的父类,从某一类派生出来 ...

  6. oracle插入中文乱码

    执行sql: select  userenv('language')     from dual;  --  AMERICAN_AMERICA.ZHS16GBK select * from v$nls ...

  7. js 时间戳 随机数 new Date().getTime()

    一:时间转时间戳:javascript获得时间戳的方法有四种,都是通过实例化时间对象 new Date() 来进一步获取当前的时间戳 1.var timestamp1 = Date.parse(new ...

  8. nodejs 安装 淘宝镜像

    临时使用 npm --registry https://registry.npm.taobao.org install express 2.持久使用 npm config set registry h ...

  9. vs2008控件查看器

    使用 OLE/COM 对象查看器 通过读取控件的类型库,OLE/COM 对象查看器使您得以查看控件的接口. 使用 OLE/COM 对象查看器 单击“工具”菜单上的“OLE/COM 对象查看器”或在命令 ...

  10. 用固定长度的数组实现stack queue

    package my_basic.class_3; /** * 用数组结构实现大小固定的队列和栈 */ public class Code_01_Array_stack_queue { public ...