Robots on a grid(DP+bfs())
链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585
Current Server Time: 2013-08-27 20:42:26
Robots on a grid
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick's Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
You have recently made a grid traversing robot that can find its way from the top left corner of a grid to the bottom right corner. However, you had forgotten all your AI programming skills, so you only programmed your robot to go rightwards and downwards (that's after all where the goal is). You have placed your robot on a grid with some obstacles, and you sit and observe. However, after a while you get tired of observing it getting stuck, and ask yourself "How many paths are there from the start position to the goal position?", and "If there are none, could the robot have made it to the goal if it could walk upwards and leftwards?"
Input
On the first line is one integer, 1 <= n <= 1000. Then follows n lines, each with n characters, where each character is one of '.' and '#', where '.' is to be interpreted as a walkable tile and '#' as a non-walkable tile. There will never be a wall at s, and there will never be a wall at t.
Output
Output one line with the number of different paths starting in s and ending in t (modulo 231-1) or THE GAME IS A LIE if you cannot go from s to t going only rightwards and downwards but you can if you are allowed to go left and up as well, or INCONCEIVABLE if there simply is no path from s to t.
Sample Input
Sample Input 1
5
.....
#..#.
#..#.
...#.
..... Sample Input 2
7
......#
####...
.#.....
.#...#.
.#.....
.#..###
.#.....
Sample Output
Sample Output 1
6 Sample Output 2
THE GAME IS A LIE 尼玛,这网页有问题!!!一个图竟然有这么大!!!!!!!
MD!!卡了老子一下午!!!!
就是一道简单的搜索+动态规划:
就是用DFS()竟然会爆栈!!!!!
世界上最污秽的词语也无法表达我现在的心情!!!!!!!!
没什么可说的Runtime error(就是爆栈)
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<queue>
using namespace std;
int flag,n;
int c1[][]={,,-,,,,,-};
long long dp[][];
const long long sb=;
char a[][];
void bfs(int x,int y)
{
int c[][];
int i,x1,y1,x2,y2;
queue<int> Q;
memset(c,,sizeof(c));
c[x][x]=;
while(!Q.empty()) Q.pop();
Q.push(x);
Q.push(y);
while(!Q.empty())
{
x1=Q.front();
Q.pop();
y1=Q.front();
Q.pop();
if(x1==n-&&y1==n-)
{
flag=;
return ;
}
if(flag)
return ;
for(i=;i<;i++)
{
x2=x1+c1[i][];
y2=y1+c1[i][];
if(x2>=&&x2<n&&y2>=&&y2<n&&a[x2][y2]!='#'&&!c[x2][y2])
{
c[x2][y2]=;
Q.push(x2);
Q.push(y2);
}
}
}
}
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
scanf("%s",a[i]);
memset(dp,,sizeof(dp));
dp[][]=;
for(i=;i<n;i++)
for(j=;j<n;j++)
if(a[i][j]!='#')
{
if(i->=&&a[i-][j]!='#')
dp[i][j]+=dp[i-][j];
if(j->=&&a[i][j-]!='#')
dp[i][j]+=dp[i][j-];
dp[i][j]%=sb;
}
if(dp[n-][n-]==)
{
flag=;
bfs(,);
if(flag)
printf("THE GAME IS A LIE\n");
else
printf("INCONCEIVABLE\n");
}
else
printf("%lld\n",dp[n-][n-]);
}
return ;
}
Robots on a grid(DP+bfs())的更多相关文章
- 1-9-假期训练心得(dp+bfs)
题目一:传送门 思路:就是简单的bfs,注意仔细审题,加上对转弯次数的判断. 题目二:传送门 思路:简单dp,记录每一秒每个位置接到的大饼的数量. 状态转移方程:dp[i][j]=max(dp[i][ ...
- 【BZOJ】1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛(dp/-bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1616 我觉得bfs是可过的,但是交bfs上去是wa? 然后没办法看dp,原来这bfs能和dp联系在一 ...
- CF 某套题 O :Grid (简单BFS)
题意: 从左上角跳到右下角最少需要多少步,跳的规则为:可以向四个方向的任意一个方向跳当前格子中的步数,若跳不到右下角输出IMPOSSIBLE. 题解: BFS搜索,注意判断边界,标记. 代码: #in ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- 取数字(dp优化)
取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...
- POJ 3083 -- Children of the Candy Corn(DFS+BFS)TLE
POJ 3083 -- Children of the Candy Corn(DFS+BFS) 题意: 给定一个迷宫,S是起点,E是终点,#是墙不可走,.可以走 1)先输出左转优先时,从S到E的步数 ...
- 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)
洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...
- [Codeforces722E] Research Rover (dp+组合数学)
[Codeforces722E] Research Rover (dp+组合数学) 题面 给出一个N*M的方格阵,从(1,1)出发,到(N,M)结束,从(x,y)只能走到(x+1,y)或(x,y+1) ...
- HDU 3681 Prison Break(状态压缩dp + BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 前些天花时间看到的题目,但写出不来,弱弱的放弃了.没想到现在学弟居然写出这种代码来,大吃一惊附加 ...
随机推荐
- 3,SFDC 管理员篇 - 区域划分
1,销售区域划分 Setup | Administrator | Manage Territory Territory Type : 帮助用户建立大的销售区域分类,分类顺序按照Priority进行显示 ...
- gitlab 配置
一.Gitlab的使用 具体步骤: 1.打开 Git Bash,输入~ssh -keygen 然后一直回车,直至出现图片上的内容 1) 2) 2.然后自动生成.ssh文件夹,双击文件夹 1) 2) ...
- oracle11g 修改字符集
查看当前字符集SQL语句: select * from nls_database_parameters where parameter ='NLS_CHARACTERSET'; 修改字符集操作如下,首 ...
- androidannotations 简单配置
1.build.gradle 需要添加的内容 标注的颜色是新建项目之后,build.gradle文件需要添加的内容. buildscript { repositories { jcenter() } ...
- 获取DataGridView中的的选中行
1. 获取DataGridView中的的选中行:http://blog.csdn.net/yiqijinbu/article/details/7734593 2.winform datagridvie ...
- Swift 为你的webView定制标题
有些情况下,应用中会使用webView来加载大段的文字,而且还是带各种标签的. 不能全部过滤掉,那样的话,内容就会失去原本想表达的格式. 可是,如果webView中并没有将内容的标题或其他杂项包含进那 ...
- Java核心知识点学习----线程中如何创建锁和使用锁 Lock,设计一个缓存系统
理论知识很枯燥,但这些都是基本功,学完可能会忘,但等用的时候,会发觉之前的学习是非常有意义的,学习线程就是这样子的. 1.如何创建锁? Lock lock = new ReentrantLock(); ...
- Android开发涉及有点概念&相关知识点(待写)
前言,承接之前的 IOS开发涉及有点概念&相关知识点,这次归纳的是Android开发相关,好废话不说了.. 先声明下,Android开发涉及概念比IOS杂很多,可能有很多都题不到的.. 首先由 ...
- C# 从excel里面复制的1万6千多条记录粘贴到FCKeditor里面,点保存的时候,保存不了,页面没有反应
客户那边添加公告,是直接从excel里面复制的,有1万6千多条记录,excel文件有6M多. 编辑器用的FCKeditor,也能粘贴上,就是点保存的时候,执行了一段时间就没有反映了,保存不了. 想着可 ...
- 問題排查:在 ServiceModel 客戶端配置部份中,找不到名稱 和協定 的終結點元素。
同樣都是刪掉服務參考再重建重編譯重發行,為什麼之前幾次都沒事? 這次只不過是刪掉服務參考,然後換了個名稱重建而已,做完就變這樣? 後來發現問題出在 app.config,因為之前 app.config ...