题意:从左上角走到右下角的所有方案,之允许走right 和 down 的话,如果可以走到那么输出path数,如果不能走到,那么加上允许走left 和 up看是否可以走到右下角,如果能的话输出“THE GAME IS A LIE”,如果还不能走到输出“ INCONCEIVABLE”。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
struct point {
int x,y;
};
char map[1005][1005];
long long a[1005][1005];
int vis[1005][1005];
int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
int n;
bool flag;
bool bfs(int x,int y) {
int k;
queue <point> q;
point start , node;
start.x = 0;
start.y = 0;
vis[x][y] = 1;
q.push(start);
while (!q.empty()) {
start = q.front();
q.pop();
for (k = 0; k < 4 ; k ++) {
int xx = start.x + dir[k][0];
int yy = start.y + dir[k][1];
if (!vis[xx][yy] && map[xx][yy]!='#' && xx>=0 && xx<n && yy>=0 && yy<n){
vis[xx][yy] = 1;
node.x = xx;
node.y = yy;
q.push(node);
if (xx==(n-1)&&yy==(n-1)) return true;
}
}
}
return false;
}
int main() {
int i , j;
while (scanf("%d",&n)!=EOF) {
for (i = 0 ; i < n ; i ++)
cin>>map[i];
for (i = 0 ; i < n ; i ++)
for (j = 0 ; j < n ; j ++)
a[i][j] = 0 , vis[i][j] = 0;
a[0][0] = 1;
for (j = 1 ; j < n ; j ++)
if (map[0][j]=='.') a[0][j] = 1;
else break;
for (i = 1 ; i < n ; i ++)
if (map[i][0]=='.') a[i][0] = 1;
else break;
for (i = 1 ; i < n ; i ++)
for (j = 1 ; j < n ; j ++) {
if (map[i][j]=='.') {
a[i][j] = ((a[i][j-1]%2147483647) + (a[i-1][j]%2147483647))%2147483647;
//这样 取余数 AC...受教了
}
else continue;
}//DP 过程
if (a[n-1][n-1])
printf("%lld\n",a[n-1][n-1]%2147483647);
else {
if(bfs(0 , 0))
printf("THE GAME IS A LIE\n");
else
printf("INCONCEIVABLE\n");
}
}
}