编程语言:Java
题目链接:http://poj.org/problem?id=3050
题解:暴力搜完事
结果:AC
import java.io.*;
import java.util.LinkedHashSet;
import java.util.Scanner;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static Scanner sc = new Scanner(System.in);
static int[][] a=new int[5][5];
static LinkedHashSet<String> set=new LinkedHashSet<String>();
static int[] dx={1,-1,0,0};
static int[] dy={0,0,1,-1};
public static void main(String[] args) throws IOException {
for(int i=0;i<5;i++){
for (int j = 0; j < 5; j++) {
a[i][j]=sc.nextInt();
}
}
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
dfs(i,j,1,""+a[i][j]);
}
}
out.println(set.size());
out.flush();
}
private static void dfs(int x,int y,int step, String str) {
if(step==6){
set.add(str);
return;
}
for(int i=0;i<4;i++){
int tx=x+dx[i];
int ty=y+dy[i];
if(tx>-1&&tx<5&&ty>-1&&ty<5){
dfs(tx,ty,step+1,str+a[tx][ty]);
}
}
}
}