#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

const int maxn=55;
int n,m,t,x1,y1,x2,y2;
struct node
{
int x,y;
int zb;
int step;
} ft,et;
char ap[maxn][maxn];
int h[11];
bool vis[1100][maxn][maxn];
int dir[4][2]= {{-1,0},{1,0},{0,-1},{0,1}};

int cal(int zb)
{
int i,j,ans=0;
for(i=0,j=1; i<10; i++,j=j*2)
if(j&zb) ans+=h[i];
return ans;
}
void bfs()
{
memset(vis,false,sizeof(vis));
int i,j,ans=-1;
ft.x=x1,ft.y=y1,ft.zb=ft.step=0;
vis[0][x1][y1]=true;
queue<node>q;
q.push(ft);
while(!q.empty())
{
ft=q.front();
q.pop();

for(i=0; i<4; i++)
{
et.x=ft.x+dir[i][0];
et.y=ft.y+dir[i][1];
if(et.x<0||et.y<0||et.x>=n||et.y>=m||ap[et.x][et.y]=='*')continue;
if(ap[et.x][et.y]!='.')et.zb=(ft.zb|(1<<(ap[et.x][et.y]-'A')));
else et.zb=ft.zb;
if(vis[et.zb][et.x][et.y])continue;
vis[et.zb][et.x][et.y]=true;
et.step=ft.step+1;
if(et.x==x2&&et.y==y2)
ans=max(ans,cal(et.zb));
if(et.step==t)continue;
q.push(et);
}
}
if(ans==-1)printf("Impossible\n");
else printf("The best score is %d.\n",ans);
}
int main()
{
int T,tt=0;
scanf("%d",&T);
while(T--)
{
int i,j,k;
scanf("%d%d%d%d",&m,&n,&t,&k);
for(i=0; i<k; i++)scanf("%d",&h[i]);
for(i=0; i<n; i++)
scanf("%s",ap[i]);
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
if(ap[i][j]=='@')
{
x1=i;
y1=j;
ap[i][j]='.';
}
else if(ap[i][j]=='<')
{
x2=i;
y2=j;
ap[i][j]='.';
}
}
}
printf("Case %d:\n",++tt);
bfs();
if(T!=0)printf("\n");
}
return 0;
}

hdu1044的更多相关文章

  1. Collect More Jewels(hdu1044)(BFS+DFS)

    Collect More Jewels Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. ubuntu下的词典的安装

    因为从事开发,安装一个词典是很有必要,文中介绍安装openyoudao和stardic两个软件的方法 一.openyoudao的安装 因为是由window转来学ubuntu的,所以总是想安装和wind ...

  2. 【Linux 工作经常使用命令 】

    1, 批量杀某个程序 比方某个程序叫  url_info.py, 起了若干个进程 . 高速查杀. 先查看 ps aux | grep url_info.py 确认没问题 ,能够杀,则批量kill ps ...

  3. .Net类的序列化和反序列化 - 进阶者系列 - 学习者系列文章

    今天看了下以前的一个工具的代码,其中涉及到.NET类的序列化和反序列化问题,所以就写一下. 这里说一下.NET类序列化的好处..NET类在序列化之前只是一个相对狭义的类.通过序列化,能够更好的保存该类 ...

  4. 通过如何通过js实现复制粘贴功能

    在ie中window.clipboardData(剪切板对象)是可以被获取,所以利用这个方法我们可以实现在IE当中复制粘贴的功能,demo如下! <html> <head> & ...

  5. 【转】Android Application 对象介绍

    What is Application Application和Activity,Service一样是android框架的一个系统组件,当android程序启动时系统会创建一个 application ...

  6. Linux根目录下文件说明

    /bin:存放最常用命令: /boot:启动Linux的核心文件: /dev:设备文件: /etc:存放各种配置文件: /home:用户主目录: /lib:系统最基本的动态链接共享库: /mnt:一般 ...

  7. Mysql彻底卸载

    -----本文摘自:http://www.heiqu.com/show-64764-1.html 1.控制面板里的增加删除程序内进行删除 2.删除MySQL文件夹下的my.ini文件,如果备份好,可以 ...

  8. Django部署到Apache Web Server

    Windows环境下,将Django部署到Apache Web Server 在Windows上部署Django(用mod_wsgi)会出现各种奇怪的问题,现简单记录下配置过程及遇到的错误及解决方法. ...

  9. Eclipse plugin web site 发布和版本更新

    Eclipse plugin web site 发布和版本更新 在eclipse插件开发过程中免不了要发布1.0, 1.1, 1.2…….等等,随着版本的递增,假如每次都发布一个插件zip包,那使用者 ...

  10. Asp.Net MVC 进阶篇:路由匹配 实现博客路径 和文章路径

    Asp.Net MVC 进阶篇:路由匹配 实现博客路径 和文章路径 我们要实现 通过路由 匹配出 博客地址 和博客文章地址 例如下面的这两个地址 //http://www.cnblogs.com/ma ...