当前位置:网站首页>DFS奇偶性剪枝
DFS奇偶性剪枝
2022-04-23 01:21:00 【OldLeft】

思路:


代码:
#include <iostream>
using namespace std;
const int N = 10;
int n, m, T;
char mat[N][N];
bool vis[N][N];
int dx[4]={
0,0,-1,1};
int dy[4]={
1,-1,0,0};
bool ok;
void dfs(int x,int y,int t){
if(ok) return;
if(t==T){
if(mat[x][y]=='D') ok=true;
return;
}
vis[x][y]=true;
for(int i=0;i<4;i++){
int tx=x+dx[i];
int ty=y+dy[i];
if(tx<0||tx>=n||ty<0||ty>=m||mat[tx][ty]=='X'||vis[tx][ty])
continue;
dfs(tx,ty,t+1);
}
vis[x][y]=false;
}
int main() {
cin >> n >> m >> T;
for (int i = 0; i < n; ++i) {
cin >> mat[i];
}
int sx,sy,ex,ey;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mat[i][j]=='S') sx=i,sy=j;
if(mat[i][j]=='D') ex=i,ey=j;
}
}
if((sx+sy+ex+ey+T)%2!=0){
//奇偶性剪枝
cout<<"NO"<<endl;
}else{
ok=false;
dfs(sx,sy,0);
if(ok)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
版权声明
本文为[OldLeft]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43833610/article/details/115771654
边栏推荐
- 轮转法分片
- Five commonly used order receiving platforms recommended by programmers
- Tdengine deployment cluster installation
- World reading day: 18 it books with Douban score above 9.0 are worth collecting
- Get in the car, the era of intelligent database autonomy has come, and Tencent cloud database x AI has made a new breakthrough
- Error: permissionerror: [winerror 32] this file is in use by another program and cannot be accessed by the process. Solution of "+ file path"
- C language guessing game and trickery game
- Yyds dry goods counting flag variable rule
- Open WebRTC Toolkit(OWT) Server User Guide
- gin框架的学习--golang
猜你喜欢

Here's the point. Have you mastered the most complete Web3 jargon guide?

Hardware SPI analysis and configuration process of imx6ull bare metal development

IMX6ULL裸机开发之GPT通用定时器分析及配置过程

API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)

CVPR | 2022 | expressed by transformer learning multiple hypotheses! A new framework for 3D human pose estimation!

Text justify, orientation, combine text attributes

GBase 8s 备份介绍

Im instant messaging development how to design a database that can support millions of concurrent users

200. Number of islands

Vs + C realizes that the form input box displays gray text by default
随机推荐
【Android工程师与智能家居产品的第一次接触③】SmartConfig一键配网在硬件端的具体实现|ESP8266一键配网在Arduino的具体实现|玉念聿辉
再谈被动安全 教你看懂中保研碰撞测试的评级报告
Interface automation session authentication solution
【服务器数据恢复】服务器硬盘进水后服务器崩溃的数据恢复案例
IMX6ULL裸机开发之硬件SPI分析及配置过程
CVPR | 2022 | expressed by transformer learning multiple hypotheses! A new framework for 3D human pose estimation!
Yyds dry goods counting flag variable rule
engine. Post() handles post requests
VRF in Mina
[ACTF2020 新生赛]Include
Text justify, orientation, combine text attributes
Gbase 8s query processing and optimization
安全用电管理平台在靖边博物馆安全用电管理系统的应用
C language guessing game and trickery game
Workplace PUA, five sins of managers
Get in the car, the era of intelligent database autonomy has come, and Tencent cloud database x AI has made a new breakthrough
京東一面:子線程如何獲取父線程 ThreadLocal 的值?我蒙了。。。
"Open source summer" activity is hot. In the registration, rich bonuses are waiting for you to get!
Interview eight part essay (disorderly order, no classification)
[interview skills] how to face an interview without a leading group