2048的升级
当n=m时则全排错,与上题一样
当n>m时,则有n-m个是排对的,剩下m个全错
import java.util.*;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int num= scanner.nextInt();for (int i=0;i<num;i++){int n= scanner.nextInt();int m=scanner.nextInt();System.out.println(Calculate(n,m));}}static int Calculate(int n,int m){if (n==m){return selectWrong(n);}else {return selectTrue(n,m)*selectWrong(m);}}static int selectTrue(int n,int m){return Factorial(n)/(Factorial(m)*Factorial(n-m));}static int Factorial(int num){if (num==1){return 1;}else {return Factorial(num-1)*num;}}static int selectWrong(int num){if (num==1){return 0;} else if (num==2) {return 1;}else {return (num-1)*(selectWrong(num-1)+selectWrong(num-2));}}
}