题意:问你n*n的国际象棋棋盘上放3个互不攻击皇后的方案数。
oeis……公式见代码内
//a(n) = 5a(n - 1) - 8a(n - 2) + 14a(n - 4) - 14a(n - 5) + 8a(n - 7) - 5a(n - 8) + a(n - 9)
//0, 0, 0, 0, 24, 204, 1024, 3628, 10320, 25096, 54400, 107880
//package acm;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void main(String[] argc){
BigInteger[] a=new BigInteger[100005];
Scanner sc = new Scanner (new BufferedInputStream(System.in));
int n=sc.nextInt();
a[0]=BigInteger.ZERO;
a[1]=BigInteger.ZERO;
a[2]=BigInteger.ZERO;
a[3]=BigInteger.ZERO;
a[4]=BigInteger.valueOf(24l);
a[5]=BigInteger.valueOf(204l);
a[6]=BigInteger.valueOf(1024l);
a[7]=BigInteger.valueOf(3628l);
a[8]=BigInteger.valueOf(10320l);
for(int i=9;i<=n;++i) {
BigInteger t1=BigInteger.valueOf(5l).multiply(a[i-1]);
BigInteger t2=BigInteger.valueOf(8l).multiply(a[i-2]);
BigInteger t3=BigInteger.valueOf(14l).multiply(a[i-4]);
BigInteger t4=BigInteger.valueOf(14l).multiply(a[i-5]);
BigInteger t5=BigInteger.valueOf(8l).multiply(a[i-7]);
BigInteger t6=BigInteger.valueOf(5l).multiply(a[i-8]);
BigInteger t7=BigInteger.valueOf(1l).multiply(a[i-9]);
a[i]=t1.subtract(t2).add(t3).subtract(t4).add(t5).subtract(t6).add(t7);
}
System.out.println(a[n]);
sc.close();
}
}
转载于:https://www.cnblogs.com/autsky-jadek/p/8343071.html