UVA 825 --Walking on the Safe Side+DP
来源:互联网 发布:英文社交软件 编辑:程序博客网 时间:2024/05/22 02:31
从一个点开始,如果始终只往右边和下边走,则如果能到达右下角距离必定是最小的,
且无论走那条路线距离都是一样的。
代码如下:
<span style="font-size:18px;">#include<iostream>#include<cstdio>#include<cstring>using namespace std;char str[100];int G[1000][1000];int dp[1000][1000];int n,m;void input(){ gets(str); sscanf(str,"%d %d",&n,&m); memset(G,0,sizeof(G)); for(int ii=1;ii<=n;ii++) { gets(str); int len=strlen(str); int temp=0,i; for(i=0;i<len;i++) { if(str[i]>='0'&&str[i]<='9') temp=temp*10+str[i]-'0'; else break; } int x=temp; temp=0; for(int j=i+1;j<=len;j++) { if(str[j]>='0'&&str[j]<='9') { temp=temp*10+str[j]-'0'; } else if(str[i]==' '||j==len) { G[x][temp]=1; temp=0; } } }}int main(){ int t; gets(str); sscanf(str,"%d",&t); while(t--) { gets(str); input(); memset(dp,0,sizeof(dp)); dp[1][1]=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(G[i][j]==1) dp[i][j]=0; else dp[i][j]+=dp[i-1][j]+dp[i][j-1]; } printf("%d\n",dp[n][m]); if(t) printf("\n"); } return 0;}</span>
1 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
- (win7)IIS7下配置php5.3
- 2015-1-27工作日志
- 安卓杂记(三)利用自定义的PolyBezier()函数将一系列散点绘制成光滑曲线(一)
- 学习python的地方
- unity3D OnTriggerEnter和OnCollisionEnter的区别
- UVA 825 --Walking on the Safe Side+DP
- http://busumen.com/20141221/18695.html 01m4xc1r
- 【Unity Shaders】ShadowGun系列之一——飞机坠毁的浓烟效果
- poj_2739 素数打表
- Unity3d中使用自带动画系统制作下雨效果(二)
- android导航动画的两种实现方式
- 【Unity】卡通风格的Shader(二)
- POJ 3767 I Wanna Go Home
- 羊癫疯治疗方法 01mauzjk