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 前些天花时间看到的题目,但写出不来,弱弱的放弃了.没想到现在学弟居然写出这种代码来,大吃一惊附加 ...
随机推荐
- java web须知细节
1.${pageContext.request.contextPath}是从这个请求路径(URL)上截取你的项目应用名的,比如你的项目名是hello,截取的结果应该就是/hello,/代表http// ...
- uva 10340 All in All
水题,从头到尾扫一遍就可以了,输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串s.例如,abcde可以得到bce,但无法得到dc. #include<a ...
- sqlserver复制报”应用复制的命令时在订阅服务器上找不到该行“解决方法
最近遇到“应用复制的命令时在订阅服务器上找不到该行”问题,报错如下: 官方给出的建议是重新同步和初始化订阅,当然,这是一种选择,但是对于动辄上百G的生产库,这种方法会消耗大量的资源和时间.可以通过定位 ...
- maven自动部署到远程tomcat教程
使用maven的自动部署功能可以很方便的将maven工程自动部署到远程tomcat服务器,节省了大量时间. 本文章适用于tomcat的7.x ,8.x, 9.x版本. 下面是自动部的步骤 1,首先,配 ...
- kali 虚拟机开启mysql:3306 供主机访问.
mysql -u root -p use mysql; update user set host='ip' where user='root'; //更新访问权限 flush privileges; ...
- MS sql server 基础知识回顾(二)-表连接和子查询
五.表连接 当数据表中存在许多重复的冗余信息时,就要考虑将这些信息建在另一张新表中,在新表中为原表设置好外键,在进行数据查询的时候,就要使用到连接了,表连接就好像两根线,线的两端分别连接两张表的不同字 ...
- [INS-32025] 所选安装与指定 Oracle 主目录中已安装的软件冲突
windows server 2008 r2 enterprise下的解决办法为:删除C:\Program Files (x86)\Oracle\Inventory\ContentsXML目录下的in ...
- [转载] 1. JebAPI 之 jeb.api
本文转载自: https://www.zybuluo.com/oro-oro/note/142707 JEB API 官方地址:https://www.pnfsoftware.com/apidoc/ ...
- Quartus 的管脚分配
与管脚分配相关的一些功能在assignments菜单下, Remove assignments... Back-Annotate Assignment... Import Assignment... ...
- Selenium2+python自动化3-解决pip使用异常
一.pip出现异常 有一小部分童鞋在打开cmd输入pip后出现下面情况:Did not provide a commandDid not provide a command?这是什么鬼?正常情况应该是 ...