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< ...
随机推荐
- node入门(三)——gulp运用实例
在上一篇<node入门(二)——gulpfile.js初探>中,我们知道了(看懂入门二及其参考资料)怎么运用gulp来更高效的开发,现在来示范一下. 在package.json里面配置好d ...
- CF782A Andryusha and Socks
题意: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to ...
- vmware桥接模式下主机有多个网卡导致虚拟机网络不通
桥接模式下,vmware会绑定一个物理网卡,因此有多个物理网卡时就要注意当前绑定的物理网卡.打开如下vmware菜单 可以看到VMnet0是桥接模式用的,然后他可以选择绑定一个物理网卡,注意要正确选择 ...
- el-select,选择一行,取值行的对象.
<el-select v-model="set_invoice_form.InvoiceType" placeholder="请选择" :disabl ...
- 【转载】Hierarchal Temporal Memory (HTM)
最近在看机器学习,看能否根据已有的历史来预测Hardware的故障发生概率.下文是一篇很有意思的文章,转自 http://numenta.org/htm.html. NuPIC是一个开源项目,用来实现 ...
- General mistakes in parallel computing
这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=97 March 11, 2013 General mistakes in ...
- Sql Server RowNumber和表变量分页性能优化小计
直接让代码了,对比看看就了解了 当然,这种情况比较适合提取字段较多的情况,要酌情而定 性能较差的: WITH #temp AS ( ...
- C# string日期格式
百分数格式应该用“p”这个参数. 格式 原始 数据 结 果 "{0:P}" 0.40 40% 数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $1 ...
- ML-学习提纲2
https://machinelearningmastery.com/a-tour-of-machine-learning-algorithms/ http://blog.csdn.net/u0110 ...
- 1-3 编程基础 makefile工程管理
GNU make Linux程序员必须学会使用GNU make来构建和管理自己的软件工程.GNU的make能够使整个工程的编译.链接只需要一个命令就可以完成. makefile make在执行时,需要 ...