链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585

Current Server Time: 2013-08-27 20:42:26

Robots on a grid

Time Limit: 3000ms
Memory Limit: 65536KB
 
64-bit integer IO format: %lld      Java class name: Main
Font Size: + -
Type:  
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?"

 
So you decide to write a program that, given a grid of size nn with some obstacles marked on it where the robot cannot walk, counts the different ways the robot could go from the top left corner s to the bottom right t, and if none, tests if it were possible if it could walk up and left as well. However, your program does not handle very large numbers, so the answer should be given modulo 231-1.

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. 1-9-假期训练心得(dp+bfs)

    题目一:传送门 思路:就是简单的bfs,注意仔细审题,加上对转弯次数的判断. 题目二:传送门 思路:简单dp,记录每一秒每个位置接到的大饼的数量. 状态转移方程:dp[i][j]=max(dp[i][ ...

  2. 【BZOJ】1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛(dp/-bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1616 我觉得bfs是可过的,但是交bfs上去是wa? 然后没办法看dp,原来这bfs能和dp联系在一 ...

  3. CF 某套题 O :Grid (简单BFS)

    题意: 从左上角跳到右下角最少需要多少步,跳的规则为:可以向四个方向的任意一个方向跳当前格子中的步数,若跳不到右下角输出IMPOSSIBLE. 题解: BFS搜索,注意判断边界,标记. 代码: #in ...

  4. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  5. 取数字(dp优化)

    取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...

  6. POJ 3083 -- Children of the Candy Corn(DFS+BFS)TLE

    POJ 3083 -- Children of the Candy Corn(DFS+BFS) 题意: 给定一个迷宫,S是起点,E是终点,#是墙不可走,.可以走 1)先输出左转优先时,从S到E的步数 ...

  7. 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)

    洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...

  8. [Codeforces722E] Research Rover (dp+组合数学)

    [Codeforces722E] Research Rover (dp+组合数学) 题面 给出一个N*M的方格阵,从(1,1)出发,到(N,M)结束,从(x,y)只能走到(x+1,y)或(x,y+1) ...

  9. HDU 3681 Prison Break(状态压缩dp + BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 前些天花时间看到的题目,但写出不来,弱弱的放弃了.没想到现在学弟居然写出这种代码来,大吃一惊附加 ...

随机推荐

  1. NHibernate系列文章十八:NHibernate关系之一对多(附程序下载)

    摘要 这篇文章介绍NHibernate最实用的内容:关系映射. NHibernate的关系映射方式有三种: Set:无序对象集合,集合中每一个元素不能重复. List:有序对象集合,集合中的元素可以重 ...

  2. c++子类调用基类方法的一个例子

        Base.h #pragma once   class Base { public:     Base(void);     ~Base(void);     bool CreatClone( ...

  3. ecshop 商品页面添加商品标签:

    /* @脚垫客户 需要给商品加属性.最简单粗暴的办法.后台调用加入.界面没有美化. */ goods.dwt <ul class="quantity"> <h2& ...

  4. jafka消息结构

  5. Linux C学习笔记07--管道通信

    管道通信属于进程间通信的一种方式,使用方便,但是局限是父进程与子进程间的通信,下面是调试好的代码. 程序父进程创建2个管道,分别用于父进程写数据--子进程读数据和子进程写数据--父进程读数据: #in ...

  6. 3.Mybatis全局配置文件属性详解(SqlMapConfig.xml)

    首先我们要知道一点,该配置文件的中属性的存放是有顺序的,没有办法随意的乱放.如果你属性的配置位置出错,会有如下错误提示: The content of element type "confi ...

  7. [转] Python包和类的基本用法

    http://blog.csdn.net/liukang325/article/details/46724365 建立一个文件夹filePackage 在filePackage 文件夹内创建 __in ...

  8. Java NIO教程 文件系统

    在NIO.2的文件系统中,Path是一切操作的基础.Path准确来说,代表着文件系统中的位置.可以代表一个目录(也就是通常所说的文件夹),也可以代表一个文件. 在新文件系统中,还有一个不得不说的就是F ...

  9. R语言学习笔记-变量的作用域

    R语言是如何将变量值和变量绑定的 在r语言中,当前的 workspace就是global enviroment,当输入变量名时,首先会在global enviroment中搜索该变量,如有,则将它显示 ...

  10. 【POJ3237】Tree(树链剖分)

    题意:在一棵N个节点,有边权的树上维护以下操作: 1:单边修改,将第X条边的边权修改成Y 2:区间取反,将点X与Y在树上路径中的所有边边权取反 3:区间询问最大值,询问X到Y树上路径中边权最大值 n& ...