acdream 1124 BFS + 简单DP
来源:互联网 发布:网络电视pc客户端 编辑:程序博客网 时间:2024/05/17 08:41
题意:从左上角走到右下角的所有方案,之允许走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");elseprintf("INCONCEIVABLE\n");}}}
- acdream 1124 BFS + 简单DP
- acdream 1025 Transform 简单dp
- acdream 1681(bfs)
- ACdream群OJ-完美数-简单数位dp
- ACdream DP专题训练
- XMUT acdream DP专场
- ACdream 1412 DP
- ACdream 1025 Transform (dp)
- Acdream 1191 Dragon Maze bfs
- acdream 1242 Driving Straight bfs
- ACdream简单题目集
- ACdream 简单数据结构 专题
- ACdream 简单数论 专题
- ACdream 1213 简单数学
- acdream 1222 Quantization Problem [dp]
- acdream 1218 DFA+DP
- acdream 1409 Musical 状压DP
- ACdream 1429 Rectangular Polygon (DP)
- apply和call的区别在哪
- 黑马程序员--HTML基础标签
- 禁止横屏和竖屏切换,竖屏后横屏防止再次启动activity
- FCKEditor使用汇总
- Openssl-rc4
- acdream 1124 BFS + 简单DP
- 项目管理个人的一些体会...
- MFC下创建一个简单的窗口
- 将properties文件打入jar包,并能读取
- boost.bind用法
- Spring 中加载资源文件
- poj1656----二维线段树
- 优先队列(堆) - C语言实现(摘自数据结构与算法分析 C语言描述)
- 1003 Max Sum