hdu 1502 java大数+简单dp(最长公共子序列类似)

dp[i][j][k]定义三个函数的大小,在转移过程只要保证题设条件即可

import java.math.BigInteger;
import java.util.Scanner;


public class Main
{
		public static void main (  String[] args )
		{
				Scanner cin = new Scanner (System.in );
				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.ZERO;
							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]);
						}
					}
				}
				while ( cin.hasNext ( ) )
				{
					int x = cin.nextInt ();
					System.out.println ( dp[x][x][x] );
					System.out.println ( );
				}
				
		}
}


你可能感兴趣的:(java,动态规划,最长公共子序列,大数类)