当前位置:网站首页>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
边栏推荐
- Introduction to gbase 8s shared memory buffer pool
- 世界读书日:18本豆瓣评分9.0以上的IT书值得收藏
- Here's the point. Have you mastered the most complete Web3 jargon guide?
- Vs + C realizes that the form input box displays gray text by default
- Introduction to PCIe xdma IP core (with list) - mingdeyang science and Education (mdy edu. Com)
- Detailed explanation of the usage of C language getchar
- Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
- 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
- Itextsharp page setup
- Gbase 8s fragment table management operation
猜你喜欢

智能手表的下半场,机遇与挑战并存

Fault analysis | federated storage engine table causes the monitoring thread to be in the opening table state

Soatest preliminary understanding

Detailed explanation of Milvus 2.0 quality assurance system

Ampere computing releases the computing power of observation cloud "core" and jointly promotes the development of observability

What is October 24th? Why are there no senior programmers in China in their fifties and sixties, while foreigners,,, Yu Nianyu Hui take you to celebrate the 1024 programmer Festival

gin框架的学习--golang

Chris LATTNER, father of llvm: the golden age of compilers

Completely uninstall antidote 10? What if the antidote uninstall is not clean?

Innovative practice of short video content understanding and generation technology in meituan
随机推荐
Is the stable currency a super opportunity to accelerate the death of the public chain or replace BTC?
修改数组(并查集)
Here's the point. Have you mastered the most complete Web3 jargon guide?
Configuration of imx6ull bare metal development analysis and configuration process of elcdif lighting RGB LCD
GBASE 8s 并发控制之封锁操作
Introduction to gbase 8s checkpoint
"Self abuse artifact" exploded overnight: control your face with a handle, take your own code, and bear the consequences
[course summary] Hello harmonyos series of courses, take you to zero foundation introduction
Gbase 8s检查点简介
光猫超级帐号密码,重置光猫获取超级帐号密码
清研环境深交所上市:年营收1.8亿 市值41亿
Gbase 8s数据库日志简介及管理
Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
Detailed explanation of Milvus 2.0 quality assurance system
Live broadcast software | IPTV live broadcast software | TV live broadcast | tvplayer IPTV easyplayer | youwo live broadcast | customized development of super live broadcast software
What kind of project is suitable for automated testing?
Let's talk about passive safety again. I'll teach you to understand the rating report of China Insurance Research Institute collision test
World reading day: 18 it books with Douban score above 9.0 are worth collecting
Slow response of analysis API
引爆炸弹(DFS)