程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 2102 A計劃 (dfs)

hdu 2102 A計劃 (dfs)

編輯:C++入門知識

注意傳送的時候一定要傳送過去。如果另外一邊還是傳送門的話 也是死路。

注意判斷終點的時候 還要層數一樣


#include 
#include 
#include 
#include 
#include 
using namespace std;

char map[2][12][12];
bool vis[2][12][12];
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
int lim;
int n,m;
int stx,sty,stc,tgx,tgy,tgc;

bool ok(int x,int y)
{
    if(x=0 && y=0)return true;
    return false;
}
bool dfs(int posx,int posy,int posc,int dep)
{
    if(posx==tgx && posy==tgy && posc==tgc && dep<=lim)return true;
    else if(dep>lim)return false;

    for(int d=0;d<4;d++)
    {
        int x=posx+dx[d];
        int y=posy+dy[d];

        if(ok(x,y) && map[posc][x][y]=='#' && map[1-posc][x][y]!='*' && !vis[1-posc][x][y] && map[1-posc][x][y]!='#')
        {
            vis[1-posc][x][y]=true;

            if(dfs(x,y,1-posc,dep+1))return true;

            vis[1-posc][x][y]=false;
        }
        else if(ok(x,y) && map[posc][x][y]!='#' && map[posc][x][y]!='*' && !vis[posc][x][y])
        {
            vis[posc][x][y]=true;

            if(dfs(x,y,posc,dep+1))return true;

            vis[posc][x][y]=false;
        }
    }

    return false;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&lim);

        for(int i=0;i

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved