标签:des style color io os ar java strong for
4 5 17 @A.B. a*.*. *..*^ c..b* 4 5 16 @A.B. a*.*. *..*^ c..b*
16 -1
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<queue> #include<vector> using namespace std; #define LL __int64 #define N 25 #define M 10000000 const int inf=(int)1e9; char g[N][N]; int n,m,t; int dir[4][2]={0,1,0,-1,-1,0,1,0}; int mark[N][N][1025]; struct node { int x,y,t; //时间 LL s; //状态 friend bool operator<(node a,node b) { return a.t>b.t; } }; void inti(int l) { int i,j,k; for(i=0;i<n;i++) { for(j=0;j<m;j++) { for(k=0;k<(1<<l);k++) mark[i][j][k]=inf; } } } int bfs(int x,int y) { int i,di,dj; priority_queue<node>q; node cur,next; cur.t=cur.s=0; cur.x=x; cur.y=y; q.push(cur); mark[x][y][0]=0; while(!q.empty()) { cur=q.top(); q.pop(); for(i=0;i<4;i++) { next.x=di=cur.x+dir[i][0]; next.y=dj=cur.y+dir[i][1]; next.t=cur.t+1; next.s=cur.s; if(di<0||di>=n||dj<0||dj>=m) continue; if(g[di][dj]=='*'||next.t>=t) continue; if(g[di][dj]=='^') return next.t; if(g[di][dj]>='a'&&g[di][dj]<='j') { int k=g[di][dj]-'a'; if((next.s&(1<<k))==0) { next.s|=(1<<k); } } if(g[di][dj]>='A'&&g[di][dj]<='J') { int k=g[di][dj]-'A'; if((next.s&(1<<k))==0) continue; } if(next.t<mark[di][dj][next.s]) { mark[di][dj][next.s]=next.t; q.push(next); } //printf("%c %d %d t=%d s=%d \n",g[di][dj],di,dj,next.t,next.s); } } return -1; } int main() { int i,j,k; int si,sj; while(scanf("%d%d%d",&n,&m,&t)!=-1) { for(i=k=0;i<n;i++) { scanf("%s",g[i]); for(j=0;j<m;j++) { if(g[i][j]=='@') { si=i;sj=j; } if(g[i][j]>='A'&&g[i][j]<='J') k=max(k,g[i][j]-'A'); } } inti(k+1); printf("%d\n",bfs(si,sj)); } return 0; }
标签:des style color io os ar java strong for
原文地址:http://blog.csdn.net/u011721440/article/details/39585757