HDU1885 Key Task(BFS+ 상태 압축)

1641 단어 ACM---도론
HDU1429와 거의 동일합니다.
코드:
#include
#include
#include
#include
#include
using namespace std;
const int MAX=100+10;
struct point
{
    int x,y,step,state;
    point(int x=0,int y=0,int step=0,int state=0):x(x),y(y),step(step),state(state){};
};
char g[MAX][MAX];
int vis[MAX][MAX][20];
int dirx[4]={0,1,0,-1};
int diry[4]={1,0,-1,0};
int n,m;
int sx,sy;
bool judgein(int x,int y)
{
    return 0<=x&&x que;
    vis[sx][sy][0]=1;
    que.push(point(sx,sy,0,0));
    while(!que.empty())
    {
        point top=que.front();
        que.pop();
        int x=top.x;
        int y=top.y;
        int step=top.step;
        int state=top.state;
        if(g[x][y]=='X')
        {
            return step;
        }
        for(int i=0;i<4;i++)
        {
            int nx=x+dirx[i];
            int ny=y+diry[i];
            int nstep=step+1;
            int nstate=state;
            if(judgein(nx,ny)&&g[nx][ny]!='#'&&!vis[nx][ny][nstate])
            {
                if(g[nx][ny]=='.'||g[nx][ny]=='X')
                {
                    vis[nx][ny][nstate]=1;
                    que.push(point(nx,ny,nstep,nstate));
                }
                else if(g[nx][ny]>='A'&&g[nx][ny]<='Z')
                {
                    int key=nstate&(1<='a'&&g[nx][ny]<='z')
                {
                    nstate=nstate|(1<

좋은 웹페이지 즐겨찾기