uva 825 - Walking on the Safe Side(dp)
题目链接:825 - Walking on the Safe Side
题目大意:给出n,m,现在给出n行数据, 每行有k(k为不定值)个数字, 第一个数字代表行数, 后面k - 1个数代表当前行的这个位置不可走, 问有多少路径可以从(1,1)到(n,m),只能向下或向右。
解题思路:dp[i][j] = dip[i - 1][j] + dp[i][j - 1], 很简单的dp问题。
#include <stdio.h>
#include <string.h>
const int N = 1005; int n, m, dp[N][N], g[N][N]; void handle(int k, char str[]) {
int len = strlen(str), num = 0;
for (int i = 0; i <= len; i++) {
if (str[i] >= '0' && str[i] <= '9')
num = num * 10 + str[i] - '0';
else {
g[k][num] = 1;
num = 0;
}
}
} void read() {
int r;
char str[N];
memset(dp, 0, sizeof(dp));
memset(g, 0, sizeof(g));
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &r);
gets(str);
handle(r, str);
}
} int solve () {
dp[0][1] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (g[i][j]) continue;
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[n][m];
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
read();
printf("%d\n", solve());
if (cas) printf("\n");
}
return 0;
}
uva 825 - Walking on the Safe Side(dp)的更多相关文章
- 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 - Walking on the Safe Side
题目:在一个N*M的网格中,从左上角走到右下角,有一些点不能经过,求最短路的条数. 分析:dp,帕斯卡三角.每一个点最短的就是走N条向下,M条向右的路. 到达每一个点的路径条数为左边和上面的路径之和. ...
- UVA 825 Walkiing on the safe side
根据地图,要求固定两点间最短路径的条数 . 这题的输入数据就是个坑,题目有没有说明数据之间有多个空格,结尾换行符之前也不止一个空格,WA了好几遍,以后这种情况看来都要默认按照多空格的情况处理了. 可以 ...
- UVA - 825Walking on the Safe Side(dp)
id=19217">称号: UVA - 825Walking on the Safe Side(dp) 题目大意:给出一个n * m的矩阵.起点是1 * 1,终点是n * m.这个矩阵 ...
- UVa 825【简单dp,递推】
UVa 825 题意:给定一个网格图(街道图),其中有一些交叉路口点不能走.问从西北角走到东南角最短走法有多少种.(好像没看到给数据范围...) 简单的递推吧,当然也就是最简单的动归了.显然最短路长度 ...
- UVA.357 Let Me Count The Ways (DP 完全背包)
UVA.357 Let Me Count The Ways (DP 完全背包) 题意分析 与UVA.UVA.674 Coin Change是一模一样的题.需要注意的是,此题的数据量较大,dp数组需要使 ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
- UVa 1252 - Twenty Questions(状压DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- sqlmap新手注入
一 什么是sqlmap sqlmap is an open source penetration testing tool that automates the process of detectin ...
- SQL Server 无法启动之TCP端口占用
场景再现: ---------------------------------------------------------------------------------------------- ...
- rabbitmq问题之HTTP access denied: user 'guest' - User can only log in via localhost
问题: 昨天安装rabbitmq(3.3.4版本)服务,并启用rabbitmq_management插件去管理rabbitmq服务,但是在访问管理界面使用guest用户登录时出现login faile ...
- 我的android studio
- Android05-UI02布局,自定义控件,ListView
1.布局 布局的内部除了放置控件外,也可以放置布局,通过多层布局的嵌套,我们就能够完成一些 比较复杂的界面实现 ¨四种基本布局 LinearLayout RelativeLayout FrameLay ...
- Flex中如何通过showAllDataTips属性使鼠标移动到图表时显示所有的数据Tips的例子
原文 http://blog.minidx.com/2008/11/10/1616.html 接下来的例子演示了Flex中如何通过showAllDataTips属性,使鼠标移动到图表时显示所有的数据T ...
- java操作mysql的增删改查
prepareStatement(sql)是statement的子类,比statement好用. 如果数据库中定义的是int值,那么sql语句中要把int单独提出来.如".....value ...
- Python中文字符的理解:str()、repr()、print
Python中文字符的理解:str().repr().print 字数1384 阅读4 评论0 喜欢0 都说Python人不把文字编码这块从头到尾.从古至今全研究通透的话是完全玩不转的.我终于深刻的理 ...
- javaScript 工作必知(三) String .的方法从何而来?
String 我们知道javascript 包括:number,string,boolean,null,undefined 基本类型和Object 类型. 在我的认知中,方法属性应该是对象才可以具有的 ...
- AngularJs(八) 过滤器filter创建
大纲 示例 过滤器的使用 创建过滤器 demo 这是整个示例demo 1.filter.js文件 angular.module("exampleApp", []) .constan ...