HDU-3681-Prison Break(BFS+状压DP+二分)

在一个由机器人组成的王国中,国王被人类捕获并改造为暴君。最聪明的机器人Micheal#1计划逃狱,需要制定最优路径方案,关闭所有电源开关才能逃脱。通过BFS预处理关键位置间距离,并使用状态压缩DP进行二分搜索确定最小电池容量。
Problem Description
Rompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thinking circuit was changed by human and thus became a tyrant. All those who are against him were put into jail, including our clever Micheal#1. Now it’s time to escape, but Micheal#1 needs an optimal plan and he contacts you, one of his human friends, for help.
The jail area is a rectangle contains n×m little grids, each grid might be one of the following: 
1) Empty area, represented by a capital letter ‘S’. 
2) The starting position of Micheal#1, represented by a capital letter ‘F’. 
3) Energy pool, represented by a capital letter ‘G’. When entering an energy pool, Micheal#1 can use it to charge his battery ONLY ONCE. After the charging, Micheal#1’s battery will become FULL and the energy pool will become an empty area. Of course, passing an energy pool without using it is allowed.
4) Laser sensor, represented by a capital letter ‘D’. Since it is extremely sensitive, Micheal#1 cannot step into a grid with a laser sensor. 
5) Power switch, represented by a capital letter ‘Y’. Once Micheal#1 steps into a grid with a Power switch, he will certainly turn it off. 

In order to escape from the jail, Micheal#1 need to turn off all the power switches to stop the electric web on the roof—then he can just fly away. Moving to an adjacent grid (directly up, down, left or right) will cost 1 unit of energy and only moving operation costs energy. Of course, Micheal#1 cannot move when his battery contains no energy. 

The larger the battery is, the more energy it can save. But larger battery means more weight and higher probability of being found by the weight sensor. So Micheal#1 needs to make his battery as small as possible, and still large enough to hold all energy he need. Assuming that the size of the battery equals to maximum units of energy that can be saved in the battery, and Micheal#1 is fully charged at the beginning, Please tell him the minimum size of the battery needed for his Prison break.
 

Input
Input contains multiple test cases, ended by 0 0. For each test case, the first line contains two integer numbers n and m showing the size of the jail. Next n lines consist of m capital letters each, which stands for the description of the jail.You can assume that 1<=n,m<=15, and the sum of energy pools and power switches is less than 15.
 

Output
For each test case, output one integer in a line, representing the minimum size of the battery Micheal#1 needs. If Micheal#1 can’t escape, output -1.
 

Sample Input
 
   
5 5 GDDSS SSSFS SYGYS SGSYS SSYSS 0 0
 

Sample Output
 
   
4
 

Source
 

思路:先用BFS预处理出F、G、Y之间的距离。然后二分结果用状压DP验证结果是否可行就可以 。


#include <stdio.h>
#define max(A,B)(A>B?

A:B) #define INF 999999999 struct S{ int x,y,step; }que[1000000],t; char mp[15][20]; int n,m,dis[15][15],d[20][20],type[20],pos[20],cnt,ok,dp[1<<16][20],nxt[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; bool vis[15][15]; void bfs(int sx,int sy) { int i,j,top=0,bottom=1; for(i=0;i<n;i++) for(j=0;j<m;j++) vis[i][j]=0,dis[i][j]=INF; que[0].x=sx; que[0].y=sy; que[0].step=0; dis[sx][sy]=0; vis[sx][sy]=1; while(top<bottom) { t=que[top]; t.step++; for(i=0;i<4;i++) { t.x+=nxt[i][0]; t.y+=nxt[i][1]; if(t.x>=0 && t.x<n && t.y>=0 && t.y<m && mp[t.x][t.y]!='D' && !vis[t.x][t.y]) { vis[t.x][t.y]=1; dis[t.x][t.y]=t.step; que[bottom++]=t; } t.x-=nxt[i][0]; t.y-=nxt[i][1]; } top++; } } bool check(int x) { int i,j,k; for(i=0;i<(1<<cnt);i++) for(j=0;j<cnt;j++) dp[i][j]=-1; for(i=0;i<cnt;i++)//起点到G、Y之后剩下的能量 { dp[1|(1<<i)][i]=x-d[0][i]; if(type[i]==1 && dp[1|(1<<i)][i]>=0) dp[1|(1<<i)][i]=x; } for(i=1;i<(1<<cnt);i++) { if((i&1)==0) continue;//起点不在集合内 for(j=0;j<cnt;j++) { if(dp[i][j]<0) continue;//该状态不能扩展 if((i&ok)==ok) return 1; if(i&(1<<j))//j在集合内 { for(k=1;k<cnt;k++) { if((i&(1<<k))==0)//k不在集合内 { if(dp[i][j]>=d[j][k]) { dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]-d[j][k]); if(type[k]==1) dp[i|(1<<k)][k]=x;//假设是能量池 } } } } } } return 0; } int main() { int i,j; while(~scanf("%d%d",&n,&m) && n) { for(i=0;i<n;i++) scanf("%s",mp[i]); cnt=1; ok=0; for(i=0;i<n;i++) for(j=0;j<m;j++) { if(mp[i][j]=='F') { ok|=1; type[0]=0; pos[0]=i*20+j; } else if(mp[i][j]=='G') { type[cnt]=1; pos[cnt]=i*20+j; cnt++; } else if(mp[i][j]=='Y') { ok|=(1<<cnt); type[cnt]=2; pos[cnt]=i*20+j; cnt++; } } for(i=0;i<cnt;i++) { bfs(pos[i]/20,pos[i]%20); for(j=0;j<cnt;j++) d[i][j]=dis[pos[j]/20][pos[j]%20]; } int l,r,mid,ans; l=0; ans=r=n*m; while(l<=r) { mid=(l+r)>>1; if(check(mid)) { ans=mid; r=mid-1; } else l=mid+1; } printf("%d\n",ans<n*m?ans:-1); } }



内容概要:本文围绕EKF SLAM(扩展卡尔曼滤波同步定位与地图构建)的性能展开多项对比实验研究,重点分析在稀疏与稠密landmark环境下、预测与更新步骤同时进行与非同时进行的情况下的系统性能差异,并进一步探讨EKF SLAM在有色噪声干扰下的鲁棒性表现。实验考虑了不确定性因素的影响,旨在评估不同条件下算法的定位精度与地图构建质量,为实际应用中EKF SLAM的优化提供依据。文档还提及多智能体系统在遭受DoS攻击下的弹性控制研究,但核心内容聚焦于SLAM算法的性能测试与分析。; 适合人群:具备一定机器人学、态估计或自动驾驶基础知识的科研人员及工程技术人员,尤其是从事SLAM算法研究或应用开发的硕士、博士研究生和相关领域研发人员。; 使用场景及目标:①用于比较EKF SLAM在不同landmark密度下的性能表现;②分析预测与更新机制同步与否对滤波器稳定性与精度的影响;③评估系统在有色噪声等非理想观测条件下的适应能力,提升实际部署中的可靠性。; 阅读建议:建议结合MATLAB仿真代码进行实验复现,重点关注态协方差传播、观测更新频率与噪声模型设置等关键环节,深入理解EKF SLAM在复杂环境下的行为特性。稀疏 landmark 与稠密 landmark 下 EKF SLAM 性能对比实验,预测更新同时进行与非同时进行对比 EKF SLAM 性能对比实验,EKF SLAM 在有色噪声下性能实验
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值