POJ3050 这题太水了
来源:互联网 发布:sql小计合计 编辑:程序博客网 时间:2024/06/10 07:48
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Hopscotch {
static int[][] grid = new int[5][5];static boolean[] vis = new boolean[2000000];static int[] tres = new int[7];static int[][] dir = new int[][] { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };static int cot;public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); sc = new Scanner(new File("files/hopscotch")); for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) grid[i][j] = sc.nextInt(); cot = 0; for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) { tres = new int[7]; tres[0] = 1; tres[1] = grid[i][j]; dfs(i, j, 1); } System.out.println(cot);}private static void dfs(int x, int y, int step) { // TODO Auto-generated method stub if (step == 6) { int tmp = 1; for (int i = 1; i < 7; i++) { tmp *= 10; tmp += tres[i]; } if (!vis[tmp]) { vis[tmp] = true; cot++; } return; } int nx, ny; for (int i = 0; i < 4; i++) { nx = x + dir[i][0]; ny = y + dir[i][1]; if (nx >= 0 && nx <= 4 && ny >= 0 && ny <= 4) { tres[step + 1] = grid[nx][ny]; dfs(nx, ny, step + 1); } }}
}
sample input:
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1
sample output:
15
0 0
- POJ3050 这题太水了
- poj3050
- poj3050
- poj3050
- POJ3050 Hopscotch
- dfs--poj3050
- POJ3050--Hopscotch
- POJ3050-Hopscotch
- Hopscotch POJ3050
- poj3050【dfs】
- POJ3050 Hopscotch
- POJ3050(dfs)
- POJ3050-Hopscotch
- POJ3050 Hopscotch 【DFS】
- poj3050 Hopscotch(dfs基础)
- poj3050解题报告
- [dfs]POJ3050 Hopscotch
- POJ3050-Hopscotch-穷竭搜索
- 归并排序求逆序对
- Unreal Engine 4 C++ 插件介绍
- 代码小积累
- 数组下标越界
- Android studio一些快捷键
- POJ3050 这题太水了
- Android---对自定义类型的list<A>排序
- Java 日期比较 (上下午篇)
- SASS基本用法
- 两台WEB服务器(LAMP)通过DNS轮询功能实现负载均衡
- 活动选择问题
- 服务器双机热备概述
- loading加载及自定义view思考
- 爬虫抓取网易云音乐民谣歌单,收听量排行