Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2692 Accepted Submission(s): 615
2 1 2 3 2 2 2 0
3 90
这道题本身的数学知识是很简单的高中数学知识。
只要先求出全排列n!,再除掉每一种个数的全排列,即a[i]!就可得出来。
主要的问题还是高精度吧,请允许我用了java。。
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner cin = new Scanner(System.in); while (cin.hasNext()) { int n = cin.nextInt(); if(n==0) break; int a[] = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { a[i] = cin.nextInt(); sum += a[i]; } BigInteger b = fac(sum); for (int i = 0; i < n; i++) b=b.divide(fac(a[i])); System.out.println(b); } cin.close(); } public static BigInteger fac(int n) { BigInteger f = BigInteger.ONE; for (; n > 1; n--) f=f.multiply(BigInteger.valueOf(n)); return f; } }