状态转移方程:dp[ i ][ j ] = dp[ i ][ j ].add(dp[ i-1 ][ j-k ]);
比以前懒了。。。。贴个大数的模板留着以后用。
做DP的时候一定要找出状态转移方程的边界之后再开始敲哇。
import java.io.*; import java.math.BigInteger; import java.util.Scanner; public class Main{ public static void main(String[] args) throws IOException{ Scanner cin = new Scanner(System.in); int n, m, t; n = cin.nextInt(); m = cin.nextInt(); BigInteger [][]dp = new BigInteger[100][1000]; if(m%2 == 1 || m/2 > n*9) { System.out.println("0"); } else { for(int i = 0; i <= 50; ++i) { for(int j = 0; j <= 450; ++j) { dp[i][j] = BigInteger.ZERO; } } m = m/2; for(int i = 1; i <= 50; ++i) { dp[i][0] = BigInteger.ONE; } for(int i = 1; i <= 9; ++i) { dp[1][i] = BigInteger.ONE; } for(int i = 2; i <= n; ++i) { for(int j = i*9; j >= 1; --j) { for(int k = 0; j-k >= 0 && k <= 9; ++k) { dp[i][j] = dp[i][j].add(dp[i-1][j-k]); } } } System.out.println(dp[n][m].multiply(dp[n][m])); } } }
URAL 1036. Lucky Tickets java.math.BigInteger模板,布布扣,bubuko.com
URAL 1036. Lucky Tickets java.math.BigInteger模板
原文:http://blog.csdn.net/zmx354/article/details/20567257