uva 825 Walking on the Safe Side
2011-10-22 22:24
393 查看
题意:有t组测试数据,每组测试数据给一个矩阵n,m。接下来给出n行,每行第一个数字为该行的编号(从1开始),然后给出这行不能走的y坐标。问,从出发点(1,1),到(n,m)有多少种不同的路径(只能往下走或者往右走)。
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=105; void fun(int,char*); bool vis ,flag ; int n,m,map ,next[2][2]={0,1,1,0}; int dp(int,int); int main() { int t,t_cnt=0; scanf("%d",&t); while(t--) { memset(flag,0,sizeof(flag)); memset(vis,0,sizeof(vis)); memset(map,0,sizeof(map)); char str[100]; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { int temp; scanf("%d",&temp); gets(str); fun(temp,str); } int ans=dp(1,1); if(t_cnt++!=0) puts(""); printf("%d\n",ans); } return 0; } void fun(int pos,char *str) { int len=strlen(str),num=0; for(int i=0;i<len;i++) { if(isdigit(str[i])) { num=num*10+str[i]-'0'; } else { if(num!=0) flag[pos][num]=1; num=0; } } if(num!=0) flag[pos][num]=1; } int dp(int x,int y) { if(vis[x][y]) return map[x][y]; else if(x==n&&y==m) {vis[x][y]=1;map[x][y]=1;return 1;} else { for(int i=0;i<2;i++) { int xx=x+next[i][0],yy=y+next[i][1]; if(!flag[xx][yy]&&xx>0&&xx<=n&&yy>0&&yy<=m) { map[x][y]+=dp(xx,yy); } } vis[x][y]=1; return map[x][y]; } }
相关文章推荐
- UVa 825 - Walking on the Safe Side
- UVa 825 - Walking on the Safe Side(简单DP+数据读入)
- UVA825- 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(动态规划:记忆化搜索)
- 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
- 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
- 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 (dp)
- uva 825 - Walking on the Safe Side(dp)