UVA-825-Walking on the Safe Side
2013-06-28 00:48
274 查看
这个题要求求出从(1,1)到(n,m)的路径数,其中存在地雷点是不可经过的
注意输出换行符的控制,输入需要自己处理
代码:
注意输出换行符的控制,输入需要自己处理
代码:
#include<cstdio> #include<cstring> #include<iostream> using namespace std; const int maxn=111; int n,m,dp[maxn][maxn]; int main() { int T,flag=0; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); memset(dp,0,sizeof(dp)); char str[1001]; getchar(); for(int i=0;i<n;i++) { gets(str); int len=strlen(str),index=0,num=0; for(int j=0;j<len;j++) { if(str[j]==' ') { if(!index) index=num; else dp[index][num]=-1; num=0; continue; } num=num*10+str[j]-'0'; } if(index&&num) dp[index][num]=-1; } dp[1][1]=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(dp[i][j]==-1) continue; if(dp[i-1][j]!=-1) dp[i][j]+=dp[i-1][j]; if(dp[i][j-1]!=-1) dp[i][j]+=dp[i][j-1]; } printf("%d\n",dp [m]); if(T) printf("\n"); } return 0; }
相关文章推荐
- 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(DP)
- Walking on the Safe Side - UVa 825 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
- 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