Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1502
Question: Each ABC letter has n numbers, and the number of numbers that meet the requirements is calculated: the number of numbers that meet the requirements of A in any prefix of the arrangement is not less than the number of B and not less than the number of C.
Idea: dp [I] [j] [k] indicates that the string is composed of I A, j B, and k C. The state transition equation is as follows: dp [I] [j] [k] = dp [I-1] [j] [k] + dp [I] [J-1] [k] + dp [I] [j] [k-1], and I> = j> = k, (that is, the end of the string is connected to a B C respectively)
Because the data is large, high precision is required. To this end, I have also learned the basics of java. Just getting started...
import java.math.BigInteger;import java.util.Scanner;public class Main{public static void main(String[] args){BigInteger [][][]dp = new BigInteger [65][65][65];dp[0][0][0] = BigInteger.ONE;for(int i = 1; i <= 60; i++){for(int j = 0; j <= i; j++){for(int k = 0; k <= j; k++){dp[i][j][k] = BigInteger.valueOf(0);if(i>j) dp[i][j][k]=dp[i][j][k].add(dp[i-1][j][k]);if(j>k) dp[i][j][k]=dp[i][j][k].add(dp[i][j-1][k]);if(k>0) dp[i][j][k]=dp[i][j][k].add(dp[i][j][k-1]);}}}Scanner cin = new Scanner(System.in);while(cin.hasNext()){int x = cin.nextInt();System.out.println(dp[x][x][x]);System.out.println();}}}