respectively 各自地 upper left corner lower right corner cell character denote restriction out hold
determine
示例1
输入
复制
3 4 DDSD AWAA WASD
输出
复制
6
说明
The 6 cells are (1, 4), (2, 1), (3, 1), (3, 2), (3, 3), (3, 4)_{}(1,4),(2,1),(3,1),(3,2),(3,3),(3,4)? respectively.
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstring>
using namespace std;
const int inf=0x3fffffff;
const int maxn=1010;int n,m;
long long res;
int tmp[maxn][maxn];
int inq[maxn][maxn];
string str[maxn];int dfs(int x,int y){
// printf("%d %d\n",x,y);if(x<0||x>=n||y<0||y>=m)return 1;if(tmp[x][y]!=0)return tmp[x][y];if(inq[x][y]==1) return -1;inq[x][y]=1;
// puts("!!");if(str[x][y]=='W') tmp[x][y]=dfs(x-1,y);else if(str[x][y]=='S') tmp[x][y]=dfs(x+1,y);else if(str[x][y]=='A') tmp[x][y]=dfs(x,y-1);else if(str[x][y]=='D') tmp[x][y]=dfs(x,y+1);return tmp[x][y];
}int main(){ios::sync_with_stdio(false);
// cin.tie(0),cout.tie(0);
// freopen("in.txt","r",stdin);cin>>n>>m;cin.ignore();for(int i=0;i<n;i++)// cin>>str[i];getline(cin,str[i]);//cout<<str[0][0];for(int i=0;i<n;i++){for(int j=0;j<m;j++){// memset(inq,0,sizeof(inq)); if(dfs(i,j)==1) {res++;}}}cout<<res<<endl;return 0;
}
/*
1 1
D
*/