UVA - 825 Walking on the Safe Side
来源:互联网 发布:网络推广 photoshop 编辑:程序博客网 时间:2024/05/16 19:11
题目大意:有一个矩阵,要求从起点走到终点,问有几条这样的路径
解题思路:本题的输入比较麻烦,随机的数目,这点要注意,从起点走到终点的最短的路径,并不是要路径都达到最小值,而是要求在只能往左或往下走的情况下能到达终点,所以用dp[i][j]表示到达该点能有几条路径,那么该点不是障碍的情况下,dp[i][j] = dp[i-1][j] + dp[i][j-1]
#include<cstdio>#include<cstring>#define maxn 1010char str[maxn];int num[maxn][maxn];int dp[maxn][maxn];int n,m;int main() {int test;scanf("%d", &test);while(test--) {int x;scanf("%d%d",&n,&m);memset(num,0,sizeof(num));for(int i = 1; i <= n; i++) {scanf("%d",&x);gets(str);int len = strlen(str);int temp = 0;for(int j = 1; j <= len; j++) if(str[j] >= '0' && str[j] <= '9')temp = temp * 10 + str[j] - '0';else {num[x][temp] = 1;temp = 0;}}memset(dp,0,sizeof(dp));dp[1][0] = 1;for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++) {if(num[i][j] == 1)dp[i][j] = 0;elsedp[i][j] = dp[i-1][j] + dp[i][j-1];}printf("%d\n",dp[n][m]);if(test)printf("\n");}return 0;}
0 0
- 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
- 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
- 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
- uva 825 Walking on the Safe Side
- UVA 825 Walking on the Safe Side
- UVA - 825 Walking on the Safe Side
- dp uva-825-Walking on the Safe Side
- UVa 825 Walking on the Safe Side (DP)
- UVA 825 Walking on the Safe Side(记忆化搜索)
- 点击FrameLayout,使其里面的控件TextView改变颜色
- 中国互联网之二十年:1994-2014
- java中equals和==的区别
- 山门
- codeforces 484D kindergarten
- UVA - 825 Walking on the Safe Side
- 图片上传的类
- Java基础——网络编程
- 最全的Webshell提权方法总结
- js中判断一个radio按钮被选中
- 正则表达式 - 示例
- Set集合中元素的保存问题(hashSet和treeSet中不能存放相同元素)
- LeetCode——Climbing Stairs
- poj3641