题目:在一个N*M的网格中,从左上角走到右下角,有一些点不能经过,求最短路的条数。

分析:dp,帕斯卡三角。每一个点最短的就是走N条向下,M条向右的路。

到达每一个点的路径条数为左边和上面的路径之和。

说明:注意数据输入格式。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio> using namespace std; int smap[101][101];
int sums[101][101]; int temp[101];
int getnumber(int tem[], char str[])
{
int move = 0,save = 0;
while (str[move]) {
while (str[move] < '0' || str[move] > '9') {
if (!str[move]) return save;
move ++;
}
int value = 0;
while (str[move] >= '0' && str[move] <= '9') {
value *= 10;
value += str[move ++]-'0';
}
tem[save ++] = value;
}
return save;
} int main()
{
int T,N,M;
char buf[1001];
scanf("%d",&T);getchar();
while (T --) { scanf("%d%d",&N,&M);getchar();
memset(smap, 0, sizeof(smap));
memset(sums, 0, sizeof(sums)); for (int i = 1 ; i <= N ; ++ i) {
gets(buf);
int count = getnumber(temp, buf);
for (int i = 1 ; i < count ; ++ i)
smap[temp[0]][temp[i]] = 1;
} sums[1][1] = 1;
for (int i = 2 ; i <= N && !smap[i][1] ; ++ i)
sums[i][1] = 1;
for (int i = 2 ; i <= M && !smap[1][i] ; ++ i)
sums[1][i] = 1;
for (int i = 2 ; i <= N ; ++ i)
for (int j = 2 ; j <= M ; ++ j) {
sums[i][j] = sums[i-1][j]+sums[i][j-1];
if (smap[i][j]) sums[i][j] = 0;
} printf("%d\n",sums[N][M]);
if (T) printf("\n");
}
return 0;
}

UVa 825 - Walking on the Safe Side的更多相关文章

  1. uva 825 - Walking on the Safe Side(dp)

    题目链接:825 - Walking on the Safe Side 题目大意:给出n,m,现在给出n行数据, 每行有k(k为不定值)个数字, 第一个数字代表行数, 后面k - 1个数代表当前行的这 ...

  2. UVA 825 Walking on the Safe Side(记忆化搜索)

      Walking on the Safe Side  Square City is a very easy place for people to walk around. The two-way ...

  3. UVA 825 Walkiing on the safe side

    根据地图,要求固定两点间最短路径的条数 . 这题的输入数据就是个坑,题目有没有说明数据之间有多个空格,结尾换行符之前也不止一个空格,WA了好几遍,以后这种情况看来都要默认按照多空格的情况处理了. 可以 ...

  4. UVa 825【简单dp,递推】

    UVa 825 题意:给定一个网格图(街道图),其中有一些交叉路口点不能走.问从西北角走到东南角最短走法有多少种.(好像没看到给数据范围...) 简单的递推吧,当然也就是最简单的动归了.显然最短路长度 ...

  5. uva 825

    这个......小学生就会的  坑在输入输出了  两个数之间可能不止一个空格....wa了好几遍啊 #include <cstdio> #include <cstring> # ...

  6. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  7. 算法入门经典大赛 Dynamic Programming

    111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...

  8. UVA - 825Walking on the Safe Side(dp)

    id=19217">称号: UVA - 825Walking on the Safe Side(dp) 题目大意:给出一个n * m的矩阵.起点是1 * 1,终点是n * m.这个矩阵 ...

  9. 紫书 习题 8-25 UVa 11175 (结论证明)(配图)

    看了这篇博客https://blog.csdn.net/u013520118/article/details/48032599 但是这篇里面没有写结论的证明, 我来证明一下. 首先结论是对于E图而言, ...

随机推荐

  1. How a C++ compiler implements exception handling

    Introduction One of the revolutionary features of C++ over traditional languages is its support for ...

  2. C++易vector

    很长一段时间没有动手编写C++计划.无非就是模仿后STL对,虽然达不到标准STL该程序.但简单的功能来实现. STL事实上,深刻:泛型编程.容器.算法.适配器...有的是内容能够学.以下是依据STL源 ...

  3. liGDX life_cycle (生命周期)

    本文章翻译自libGDX官方wiki,,转载请注明出处:http://blog.csdn.net/kent_todo/article/details/37940489 libGDX官方网址:http: ...

  4. codeforces 592B The Monster and the Squirrel

    题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律   代码: #include<bits/s ...

  5. java之jvm学习笔记五(实践写自己的类装载器)

    java之jvm学习笔记五(实践写自己的类装载器) 课程源码:http://download.csdn.net/detail/yfqnihao/4866501 前面第三和第四节我们一直在强调一句话,类 ...

  6. Caché Monitor 2.03发布,Caché的SQL开发工具 - 开源中国社区

    Caché Monitor 2.03发布,Caché的SQL开发工具 - 开源中国社区 Caché Monitor 2.03发布,Caché的SQL开发工具

  7. WOJ 1055

    #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char s[6]={0} ...

  8. Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

    參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...

  9. c#控制台应用程序-“进入指定日期检查出星期几”

    这涉及一个算法: 基姆拉尔森计算公式 W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1) mod 7 在公式中d表示日期中的日数.m表示月份数.y表示年数. 注意:在公式 ...

  10. uboot启动阶段修改启动参数方法及分析

    作者:围补 本来启动方式这节不是什么复杂的事儿,不过想简单的说清楚明白,还真是不知道怎么组织.毕竟文字跟有声语言表达有别.但愿简单的东西别让我讲的太复杂! Arm板系统文件一般有三个——bootloa ...