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& ...
随机推荐
- Diet
Dialogue 1 Healthy diet 关于健康饮食 F:Bob, look at this sentence. 'Healthy eating is not about strict n ...
- RedHat6.5网卡问题总结
问题描述:准备用RedHat6.5安装Oracle 12c RAC,系统环境准备好后发现,新版本的RedHat网卡配置跟以前不大一样,总结问题与解决方法如下: 1.找不到eth0文件 在使用RedHa ...
- Oracle EBS-SQL (PO-9):检查期间采购订单执行情况.sql
--采购订单执行情况查询(七天内接收情况)select pha.segment1 采购订单, msib.segment1 物料编码, pla.qu ...
- java猜数字小游戏
/* * * 猜数字小游戏 * * 先由系统生成一个2-100之间的随机数字, * * 然后捕获用户从控制台中输入的数字是否与系统生成的随机数字相同, * * 如果相同则统计用户所猜的次数,并给出相应 ...
- nexus 7 2013 驱动安装及root
驱动安装 Nexus 7 2013连接上电脑后,设备管理器显示新设备 nexus 7 待安装驱动(其实是MTP设备待安装驱动).去谷歌网站下载最新的USB驱动,version 8.0 的.与以前的版本 ...
- Javascript 排序数组或对象
分享一个用于数组或者对象的排序的函数.该函数可以以任意深度的数组或者对象的值作为排序基数对数组或的元素进行排序. 代码如下: /** * 排序数组或者对象 * by Jinko * date 2015 ...
- ceph for openstack快速部署实施
for el6 即centos6 1,添加ceph 官方yum源 [root@ruiy ~]# cat /etc/yum.repos.d/ceph.repo[ceph-noarch]name=Ceph ...
- 怎样学习使用libiconv库
怎样学习使用libiconv库 - My Study My Study About My Learn or Study etc. 怎样学习使用libiconv库 By Cnangel on Febru ...
- Guava缓存器源码分析——删除消息
Guava缓存器的删除消息机制 测试代码—— LoadingCache<String, Integer> cache = CacheBuilder.newBuild ...
- kubuntu/ubuntu下安装fcitx输入法
1.添加fcitx源(官方的源是旧版,不推荐使用) sudo gedit /etc/apt/sources.list 在sources.list文件中尾部添加: deb http://ppa.laun ...