UVa 825 - Walking on the Safe Side
题目:在一个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的更多相关文章
- uva 825 - Walking on the Safe Side(dp)
题目链接:825 - Walking on the Safe Side 题目大意:给出n,m,现在给出n行数据, 每行有k(k为不定值)个数字, 第一个数字代表行数, 后面k - 1个数代表当前行的这 ...
- 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 ...
- UVA 825 Walkiing on the safe side
根据地图,要求固定两点间最短路径的条数 . 这题的输入数据就是个坑,题目有没有说明数据之间有多个空格,结尾换行符之前也不止一个空格,WA了好几遍,以后这种情况看来都要默认按照多空格的情况处理了. 可以 ...
- UVa 825【简单dp,递推】
UVa 825 题意:给定一个网格图(街道图),其中有一些交叉路口点不能走.问从西北角走到东南角最短走法有多少种.(好像没看到给数据范围...) 简单的递推吧,当然也就是最简单的动归了.显然最短路长度 ...
- uva 825
这个......小学生就会的 坑在输入输出了 两个数之间可能不止一个空格....wa了好几遍啊 #include <cstdio> #include <cstring> # ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 算法入门经典大赛 Dynamic Programming
111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...
- UVA - 825Walking on the Safe Side(dp)
id=19217">称号: UVA - 825Walking on the Safe Side(dp) 题目大意:给出一个n * m的矩阵.起点是1 * 1,终点是n * m.这个矩阵 ...
- 紫书 习题 8-25 UVa 11175 (结论证明)(配图)
看了这篇博客https://blog.csdn.net/u013520118/article/details/48032599 但是这篇里面没有写结论的证明, 我来证明一下. 首先结论是对于E图而言, ...
随机推荐
- git版本号回滚
先说今天遇到的问题,看到一个config.php的配置文件一直在改动的状态下,可是和远程的config.php是不一致的,我不须要提交它,可是看它在 modified的状态下,非常不爽.想删除它.gi ...
- Eclipse 每次打开workspace目录记录位置?
E:\eclipse_j2ee eclipse安装根目录 在这个文件下: E:\eclipse_j2ee\configuration\.settings\org.eclipse.ui.ide.pref ...
- Python基础 - 内建函数
什么是内建函数 在Python的手册中,名叫build-in Functions,中文可以称为内建函数. 内建函数就像dos系统的内部命令,他不依赖于外部模块,也就是说: 内建函数就是:安装好Pyth ...
- UVa 10188 - Automated Judge Script
题目:给你一些题目的输出结果,推断是AC,PE还是WA. 分析:模拟. 依照题意模拟就可以,注意PE条件为全部数字字符出现顺序同样就可以. 说明:想起非常多年前写的OJ的后台判题程序了╮(╯▽╰)╭. ...
- poj 2038 Team Rankings 枚举排列
//poj 2038 //sep9 #include <iostream> #include <algorithm> using namespace std; char s[1 ...
- oschina jQuery 插件
jQuery 插件 jQuery自动完成插件(25) jQuery分页插件(20) jQuery 文件上传(21) jQuery 地图插件(14) jQuery对话框(109) jQuery图片展示/ ...
- exit()和_exit()和return
exit()和return的差别: 依照ANSI C,在最初调用的main()中使用return和exit()的效果同样. 但要注意这里所说的是"最初调用".假设main()在一个 ...
- 开源语法分析器--ANTLR
序言 有的时候,我还真是怀疑过上本科时候学的那些原理课究竟是不是在浪费时间.比方学完操作系统原理之后我们并不能自己动手实现一个操作系统:学完数据库原理我们也不能弄出个像样的DBMS出来:相同,学完 ...
- hdu1542(线段树——矩形面积并)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 分析:离散化+扫描线+线段树 #pragma comment(linker,"/STA ...
- Python – Get Object’s Class Name | Ridge Solutions, Ireland
Python – Get Object’s Class Name | Ridge Solutions, Ireland Python – Get Object’s Class Name Author: ...