HDU 1010 Tempter of the Bone
来源:互联网 发布:d3.js官网 编辑:程序博客网 时间:2024/06/16 20:22
以后做得很顺的题目就不发博客了,发太多有点蛋疼,都发了140多篇了。
发一些完全不会或者卡了一半的题目吧,这样便于做个总结,重在查漏补缺
Ural 和 UVA的DP分类既然开始A了,又发了那么多,后面还是会一一发出来补完。
早在2011年还在读书那会,图论和搜索写得比较多,然后荒废了1年多,之后写DP又是各种没思路,
于是如这个博客反映的一样,刷了N多DP题。
结果是2年以后搜索和图论又不会写了。。。
HDU刷了刷, 人太多了,俨然超过了POJ啊。
这个题目没啥太多说的,DFS深搜,但是没想出来怎么剪枝。。。
坐标奇偶位剪,就是这样。
import java.io.*;import java.math.BigInteger;import java.util.*; public class stackingbox { public static char[][] maze = new char[10][10]; public static int[][] dir = {{0,1},{0,-1},{-1,0},{1,0}}; public static int[][] mark = new int[10][10]; public static boolean is_legal(int a, int b, int n, int m){ if(0<=a&&a<n&&0<=b&&b<m) return true; return false; } public static int DFS(int x, int y, int step, int time, int n, int m, int d_x, int d_y){ if(maze[x][y]=='D'&&step==time){ return 1; }else if(step>=time){ return 0; } if((time-step)%2!=Math.abs((d_x+d_y-x-y)%2)) return 0; int flag = 0; for(int i=0;i<4;i++){ int next_x = x+dir[i][0]; int next_y = y+dir[i][1]; if(is_legal(next_x, next_y, n, m)&&maze[next_x][next_y]!='X'&&mark[next_x][next_y]==-1){ mark[next_x][next_y] = 1; int result = DFS(next_x, next_y, step+1, time, n, m, d_x, d_y); mark[next_x][next_y] = -1; flag|=result; if(result==1) { flag = 1; break; } } } return flag; } public static void main (String [] args) throws Exception { //System.out.println(-1|0); Scanner scan = new Scanner(System.in); while(true){ String tmp[] = scan.nextLine().split(" "); int n = Integer.parseInt(tmp[0]); int m = Integer.parseInt(tmp[1]); int t = Integer.parseInt(tmp[2]); if(n==0) break; int x=-1, y=-1, d_x=-1, d_y=-1; for(int i=0;i<n;i++){ Arrays.fill(mark[i], -1); String temp= scan.nextLine(); for(int j=0;j<m;j++){ maze[i][j] = temp.charAt(j); if(maze[i][j]=='S'){ x=i; y=j; } if(maze[i][j]=='D'){ d_x=i; d_y=j; } } } mark[x][y]=1; if(DFS(x,y,0,t,n,m,d_x,d_y)==1){ System.out.println("YES"); }else{ System.out.println("NO"); } } }}
0 0
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU-1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- hdu 1010 Tempter of the Bone
- linux删除重复行
- 《机器学习实战》k-近邻算法概述-程序清单详解kNN.py(未完待续)
- java File读写
- MediCool天使投资计划
- Apriori算法详解
- HDU 1010 Tempter of the Bone
- dbms_profiler 调整PL/SQL的性能
- 《高效程序员的45个习惯——敏捷开发修炼之道》读书总结
- 银行应对互联网金融
- ccsm ubuntu 特效软件使用记录
- SET的一些知识点
- Leetcode Palindrome Partitioning
- 使用安全令牌保护 RTMP 流
- uva10806 - Dijkstra, Dijkstra. 最小费用流 求两条路权值之和最小