设为首页 加入收藏

TOP

HDU-5025 2014广州网络赛 Saving Tang Monk 状压+BFS
2015-07-20 17:38:05 来源: 作者: 【 】 浏览:3
Tags:HDU-5025 2014 广州 网络 Saving Tang Monk 状压 BFS

给出一个N*N的矩阵,开启牢门需要收集齐m种钥匙,且必须收集了前i-1种钥匙才能收集第i种钥匙,最终收集齐了回到关押唐僧的房间拯救唐僧,经过一个'S'的房间时需要额外耗时把蛇打死,蛇最多5条,所以状压一下用优先队列BFS求最小时间即可。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #define inf 1<<29 using namespace std; const int maxn=111; char str[maxn][maxn]; int n,m; int ans; int map[maxn][maxn]; int dp[maxn][maxn][11];//访问到坐标(x,y)身上有i个钥匙的步数 int dir[4][2]= {0,1,0,-1,1,0,-1,0}; struct node { int x,y; int step; int snake; int k; friend bool operator<(node a,node b) { return a.step>b.step; } }; int go(int x,int y) { if(x>=0&&x
         
          =0&&y
          
            q; node front,now; now.x=x; now.y=y; now.step=0; now.snake=0; now.k=0; q.push(now); while(!q.empty()) { front=q.top(); q.pop(); x=front.x; y=front.y; if(str[x][y]=='T'&&front.k==m) { ans=min(ans,front.step); } for(int i=0;i<4;i++) { int fx=x+dir[i][0]; int fy=y+dir[i][1]; now.x=fx; now.y=fy; now.step=front.step+1; now.snake=front.snake; now.k=front.k; if(go(fx,fy)) { if(str[fx][fy]=='S') { int k=map[fx][fy]; if(((1<
           
            now.step&&now.step
            
             

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU5038-Grade 下一篇HDU-5040-Instrusive(BFS+优先队..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·利用python进行数据 (2025-12-25 20:49:22)
·如何使用 python 中 (2025-12-25 20:49:19)
·零基础如何学爬虫技 (2025-12-25 20:49:17)
·Java 并发工具类:提 (2025-12-25 20:25:44)
·Java面试技巧:如何 (2025-12-25 20:25:41)