第一题,直接用排列组合公式 !n^2 / (!a * !b * !c * !d) 。注意的点在于使用 BigIntener 来存数字(Java),不然那数字太大太大了。 void alibaba1() { Scanner input = new Scanner(System.in); int n = input.nextInt(); int a = input.nextInt(); int b = input.nextInt(); int c = input.nextInt(); int d = input.nextInt(); n = n * n; BigInteger facN = factorial(n); BigInteger facA = factorial(a); BigInteger facB = factorial(b); BigInteger facC = factorial(c); BigInteger facD = factorial(d); BigInteger denominator = facA.multiply(facB).multiply(facC).multiply(facD); BigInteger result = (facN.divide(denominator)).remainder(BigInteger.valueOf(998244353)); System.out.println(result); } //取阶乘 暴力就完事了 BigInteger factorial(int n) { BigInteger result = BigInteger.valueOf(1); for (int i = 1; i <= n; i++) { result = result.multiply(BigInteger.valueOf(i)); } return result; } 很笨很暴力的方法了,但是 能AC 就是好方法🤣
点赞 1

相关推荐

点赞 评论 收藏
分享
牛客网
牛客企业服务