当前位置:网站首页>DFS parity pruning
DFS parity pruning
2022-04-23 01:25:00 【OldLeft】

Ideas :


Code :
#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){
// Parity pruning
cout<<"NO"<<endl;
}else{
ok=false;
dfs(sx,sy,0);
if(ok)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
版权声明
本文为[OldLeft]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230120462331.html
边栏推荐
- JD side: comment un thread enfant obtient - il la valeur de threadlocal du thread parent? Je suis couvert...
- Good test data management, in the end how to do?
- gin框架的学习--golang
- Gbase 8t index
- gin -get请求的小示例2-Handle处理post请求
- Learning of gin framework -- golang
- App uses the template message from WeChat official account for message push.
- Chris LATTNER, father of llvm: the golden age of compilers
- 京东一面:子线程如何获取父线程 ThreadLocal 的值?我蒙了。。。
- Ampere computing releases the computing power of observation cloud "core" and jointly promotes the development of observability
猜你喜欢

In the second half of the smart watch, opportunities and challenges coexist

清研环境深交所上市:年营收1.8亿 市值41亿

New functions of ai2022, introduction to new functions of illustrator 2022

Configuration of imx6ull bare metal development analysis and configuration process of elcdif lighting RGB LCD

京東一面:子線程如何獲取父線程 ThreadLocal 的值?我蒙了。。。

JD side: comment un thread enfant obtient - il la valeur de threadlocal du thread parent? Je suis couvert...

VSCODE + PHP Debug + 名字空间指引

Practice and exploration of knowledge map visualization technology in meituan

Cai Guoqiang's fireworks NFT debut is as wonderful as fireworks during the day

API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
随机推荐
Gbase 8s shared memory segment deletion
Soatest preliminary understanding
直播软件|IPTV直播软件|电视直播|TVPlayer-IPTV-EasyPlayer|友窝直播|超级直播软件定制开发
"Self abuse artifact" exploded overnight: control your face with a handle, take your own code, and bear the consequences
Get rid of the "small workshop" of AI production: how to build a cloud native AI platform based on kubernetes
CVPR | 2022 | expressed by transformer learning multiple hypotheses! A new framework for 3D human pose estimation!
After ten years of testing experience, I have sorted out the most suitable software testing learning guide for you
VS+C# 实现窗体输入框默认显示灰色文字
Unity combines itextsharp to generate PDF preparation DLL
Project manager's thinking mode worth trying: project success equation
Introduction to gbase8s SQL Engine framework
Function encapsulation such as addition, deletion, modification and query of linked list (summary)
Articles for May
Introduction to gbase 8s storage structure and space management
计蒜客(踏青)(染色块问题的DFS和BFS解法)
Examples of branch and loop statements
Vs + C realizes that the form input box displays gray text by default
Basic operation of Android local database | multi thread operation database | addition, deletion, modification and query of database | batch insertion into database | basic use of thread pool | Yu nia
[蓝桥杯][2019年第十届真题]外卖店优先级
Huawei CDN is fast everywhere