50分求助
  • 板块P1605 迷宫
  • 楼主asd890123
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/6 21:18
  • 上次更新2024/3/7 11:27:51
查看原帖
50分求助
1074084
asd890123楼主2024/3/6 21:18

#include <stdio.h>
#include <string.h>

int n,m,t,tx,ty;
int sx,sy,fx,fy,ans=0;
int wkx[4] = {-1 , 0 , 1 , 0};
int wky[4] = {0 , 1 , 0 , -1};
bool ctrl[6][6],vis[6][6];

void dfs(int x,int y);

int main(){
    
    memset(ctrl,false,sizeof(ctrl));
    memset(vis,false,sizeof(vis));
    scanf("%d%d%d",&n,&m,&t);
    scanf("%d%d%d%d",&sx,&sy,&fx,&fy);
    for (int i=1;i<=t;i++){
        
        scanf("%d%d",&tx,&ty);
        ctrl[tx][ty] = true;
        
    }
    dfs(sx,sy);
    printf("%d",ans);
    
    return 0;
}

void dfs(int x,int y){
    
    if (x >= fx and y >= fy){
        
        ans++;
        return;
        
    }
    
    for (int i=0;i<4;i++){
        
        int a = x + wkx[i];
        int b = y + wky[i];
        if (a>=1 and b >=1 and a<=n and b <= m and !vis[a][b] and !ctrl[a][b]){
            
            vis[a][b] = true;
            dfs(a,b);
            vis[a][b] = false;
            
        }
        
    }
    
}
2024/3/6 21:18
加载中...