hdu1044

#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;
}

转载于:https://www.cnblogs.com/wangkun1993/p/6287993.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值