0% found this document useful (0 votes)
20 views1 page

03

Uploaded by

sq.zyx2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

03

Uploaded by

sq.zyx2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<bits/stdc++.

h>
using namespace std;
char g[100][100];
int sign[100][100];
int m,n,flag;
string target;
int pos[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
static void dfs(int i,int j,int now){
if(i>=n||i<0||j>=m||j<0)return;
if(sign[i][j]||g[i][j]!=target[now])return;
if(now>=target.size()-1){
flag=1;
return;
}
sign[i][j]=1;
for(int ii=0;ii<4;ii++){
dfs(i+pos[ii][0],j+pos[ii][1],now+1);
}
sign[i][j]=0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m;
flag=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>g[i][j];
}
}
cin>>target;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
dfs(i,j,0);
}
}
cout<<(flag?"true\n":"false\n");
return 0;
}

You might also like