hdu 2128 Tempter of the Bone II
来源:互联网 发布:中文域名到期查询 编辑:程序博客网 时间:2024/05/10 23:58
#include<stdio.h>#include<string.h>int N=9999999;char a[10][10];int maxn,n,m,startx,starty,endx,endy;int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};int book[10][10][1000];void dfs(int x,int y,int num,int step){ if(x==endx&&y==endy){ if(step<maxn){maxn=step;return;} } for(int i=0;i<4;i++) { int tx=x+next[i][0],ty=y+next[i][1]; if(tx>n||tx<1||ty<1||ty>m) continue; if(a[tx][ty]=='X'){ if(num<1) continue; a[tx][ty]='.'; book[tx][ty][num-1]=1; dfs(tx,ty,num-1,step+2); a[tx][ty]='X'; book[tx][ty][num-1]=0; } else if(a[tx][ty]>='1'&&a[tx][ty]<='9'){ int c=num+a[tx][ty]-'0'; a[tx][ty]='.'; book[tx][ty][c]=1; dfs(tx,ty,c,step+1); a[tx][ty]=c-num+'0'; book[tx][ty][c]=0; } else{ if(book[tx][ty][num]) continue; book[tx][ty][num]=1; dfs(tx,ty,num,step+1); book[tx][ty][num]=0; } } return ;}int main(){ while(scanf("%d%d",&n,&m)){ if(n==0&&m==0) break; for(int i=1;i<=n;i++){ scanf("%s",a[i]+1); for(int j=1;j<=m;j++) if(a[i][j]=='S'){startx=i,starty=j;} else if(a[i][j]=='D'){endx=i,endy=j;} } memset(book,0,sizeof(book)); maxn=N; dfs(startx,starty,0,0); if(maxn==N) printf("-1\n"); else printf("%d\n",maxn); } return 0;}//深搜超时
0 0
- HDU 2128 Tempter of the Bone II
- HDU 2128 Tempter of the Bone II
- HDU 2128 Tempter of the Bone II
- HDU 2128Tempter of the Bone II
- hdu 2128 Tempter of the Bone II
- HDU 2128 Tempter of the Bone II(BFS)
- HDU-2128 Tempter of the Bone II BFS
- HDU-2128-Tempter of the Bone II(BFS)
- 【搜索】 HDU 2128 Tempter of the Bone II BFS 状压
- HDU 2128 Tempter of the Bone II(BFS+状态压缩)
- HDU 2128 Tempter of the Bone II(BFS)
- [hdu]Tempter of the Bone
- HDU Tempter of the Bone
- Tempter of the Bone HDU
- Tempter of the Bone HDU
- Tempter of the Bone HDU
- Tempter of the Bone HDU
- hdoj 2128/hdu 2128 Tempter of the Bone II (附数据)
- Context namespace element 'component-scan' and its parser class [org.springframework.context.annotat
- 网站注册登录等短信验证码
- 理解With语句
- ASIC前端流程
- Go常用字符串函数操作实例
- hdu 2128 Tempter of the Bone II
- 二分法查找
- 前端性能优化五:CDN
- JVM中的GC回收分析
- Vector既然继承了AbstractList为啥还要实现List接口
- HTMLParser使用
- Mysql 主键自增量设置
- 进程、线程、多线程的引入
- Java多线程:线程状态