Error message of RPG
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5536 accepted submission (s): 2269
Problem description: this summer, the Hangzhou-Hangzhou ACM training team formed a girls' team for the first time. One of them was called RPG, but the wild camels, one of the members of the training team, did not know who the three RPG teams were. RPG gave him the opportunity to guess, the first guess: R is the princess, p is the grass, G is the moon hare; the second guess: R is the grass, p is the moon hare, G is the princess; the third guess: R is the grass, p is the princess, G is the moon hare ;...... the third time the poor wild camels finally made it clear about RPG. Thanks to RPG, there are more and more girls working on ACM. Our wild camels want to know about them, but now there are n people who want to guess more times. In order not to embarrass the wild camels, if a girl asks him to pass the examination only by half or more, how many answers can he pass the examination smoothly.
There are multiple cases in the input data. Each case includes N, which indicates that there are several girls, (n <= 25), and n = 0 indicates that the input ends.
Sample Input
120
Sample output
11
Use the wrong sorting and combination Formula
Error: A [I] = (I-1) x (A [I-1] + A [I-2]); A [0] = 0; A [1] = 0; A [2] = 2;
Combination: C (m, n) = M! /(M-N )! /N!
import java.util.*;import java.io.*;import java.math.BigInteger;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); while (sc.hasNextInt()) { int n = sc.nextInt(); int m=0; BigInteger sum=BigInteger.ONE; if (n == 0) System.exit(0); for(int i=0;i<=n/2;i++){ sum=sum.add(zhuHe(n).divide(zhuHe(n-i)).divide(zhuHe(i)).multiply(cuoPai(i))); } System.out.println(sum); } } public static BigInteger zhuHe(int m){ BigInteger big[]=new BigInteger[25+1]; big[0]=BigInteger.ONE; big[1]=BigInteger.ONE; for(int i=1;i<=m;i++){ big[i]=big[i-1].multiply(BigInteger.valueOf(i)); } return big[m]; } public static BigInteger cuoPai(int m){ BigInteger big[]=new BigInteger[26]; big[0]=BigInteger.ZERO; big[1]=BigInteger.ZERO; big[2]=BigInteger.valueOf(1); for(int i=3;i<=m;i++){ big[i]=BigInteger.valueOf((i-1)).multiply(big[i-1].add(big[i-2])); } return big[m]; }}