题意:
解法:
令(x,y)=(1,1),即当前位置.
然后模拟行走,如果(x,y+1)='#',那么将(x,y)修改为(x,y+1),
否则如果(x+1,y)='#',那么将(x,y)修改为(x+1,y).
如果不能走则结束流程.
标记上述走法走过的所有格子,
然后遍历每个格子,如果存在s[i][j]='#'但是却未被标记过,那么无解.
code:
#include <bits/stdc++.h>
#define int long long
#define PI pair<int,int>
using namespace std;
const int maxm=2e3+5;
int mark[maxm][maxm];
char s[maxm][maxm];
int n,m;
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>(s[i]+1);
}
if(s[1][1]!='#'){
cout<<"Impossible"<<endl;
return ;
}
int x=1,y=1;
mark[1][1]=1;
while(1){
if(y+1<=m&&s[x][y+1]=='#'){
y++;
mark[x][y]=1;
}else if(x+1<=n&&s[x+1][y]=='#'){
x++;
mark[x][y]=1;
}else{
break;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(s[i][j]=='#'&&!mark[i][j]){
cout<<"Impossible"<<endl;
return ;
}
}
}
cout<<"Possible"<<endl;
}
signed main(){
ios::sync_with_stdio(0);
solve();
return 0;
}