解法:从N中选出M个C[n][m],然后乘上错排公式;f[n]=(n-1)*(f[n-1]+f[n-2]);f[0]=0;f[1]=1;
import java.util.Scanner; public class hdu2049 { public static int C(int a,int b) { if (a==b) { return 1; }else if (b==1) { return a; }else { return C(a-1, b-1)+C(a-1, b); } } public static void main(String[] args) { // TODO 自动生成的方法存根 long[] aa = new long[21]; aa[1] = 0; aa[2] = 1; for (int i = 3; i < aa.length; i++) { aa[i] =(i-1)*(aa[i-1]+aa[i-2]); } Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { int N = sc.nextInt(); int M = sc.nextInt(); System.out.println(C(N,M)*aa[M]); } sc.close(); } }
标签:aa,递归,int,hdu2049,问题,nextInt,sc,public From: https://www.cnblogs.com/xiaohuangTX/p/18187955