uva 825 - Walking on the Safe Side(dp)
来源:互联网 发布:商品价签打印软件 编辑:程序博客网 时间:2024/05/22 15:25
题目链接: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;}
- dp uva-825-Walking on the Safe Side
- UVa 825 Walking on the Safe Side (DP)
- uva 825 - Walking on the Safe Side(dp)
- Uva-825 Walking on the Safe Side 水DP
- uva 825 Walking on the Safe Side(dp)
- UVA 825 Walking on the Safe Side 读入输出+DP
- UVa 825 Walking on the Safe Side(DP)
- Walking on the Safe Side - UVa 825 dp
- UVA - 825Walking on the Safe Side(dp)
- UVA - 825 Walking on the Safe Side (dp)
- UVA 825 --Walking on the Safe Side+DP
- uva 825 Walking on the Safe Side (dp)
- UVA 题目825 Walking on the Safe Side(DP)
- UVA 825 Walking on the Safe Side(DP)
- uva 825 Walking on the Safe Side
- UVA 825 Walking on the Safe Side
- UVa 825 - Walking on the Safe Side
- uva 825 - Walking on the Safe Side
- 浅析NLS_SORT、NLS_COMP(-)
- 高级JS教程2——作用域 执行环境
- linux内核源码阅读之facebook硬盘加速flashcache之八
- C/C++小知识记录
- 2013百度软件研发笔试题
- uva 825 - Walking on the Safe Side(dp)
- Cryptography,一个C#写的加解密算法的类
- 一个最简单的C#事件例子
- C# 事件等大牛
- 内存的字节存储大小端问题(二)
- ConnectionFactory获取连接的简单工厂类
- SD-sap是如何确定条件值的定价值(KWERT)的?
- BeautifulSoup总结
- QuickTime格式解析