标签:传说 blog ring 范围 国际象棋 port print next oid
import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Main { static int n; static int[] zhu ; static int[] fu; static int[] lie; static int[][] a; static int sum = 0; public static void main(String[] args) { Scanner input = new Scanner(System.in); n = input.nextInt(); int x = input.nextInt(); int y = input.nextInt(); fu = new int[2*n]; zhu = new int[2*n]; lie = new int[n+1]; a = new int[n+2][n+2]; a[x][y] = 1; a[x][y-1] = 1; a[x][y+1] = 1; a[x+1][y] = 1; a[x+1][y-1] = 1; a[x+1][y+1] = 1; a[x-1][y] = 1; a[x-1][y-1] = 1; a[x-1][y+1] = 1; //i+j-1; //j-i+n; f(1); System.out.println(sum); } public static void f(int i){ for(int j=1;j<=n;j++){ if(a[i][j]==1||lie[j]==1||fu[i+j-1]==1||zhu[j-i+n]==1) continue; lie[j] = 1; fu[i+j-1] = 1;zhu[j-i+n] = 1; if(i==n){ sum++; }else{ f(i+1); } lie[j] = 0;fu[i+j-1] = 0;zhu[j-i+n] = 0; } } }
标签:传说 blog ring 范围 国际象棋 port print next oid
原文地址:http://www.cnblogs.com/lolybj/p/6542126.html