URAL1012. K-based Numbers. Version 2
考查大数 正好拿来学习下JAVA JAVA好高端。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import java.io.*; 2 import java.math.*; 3 import java.text.*; 4 import java.util.*; 5 public class Main 6 { 7 8 public static void main(String[] args) 9 { 10 Scanner cin = new Scanner (System.in); 11 BigInteger[][] dp; 12 int n,k,i,j,g; 13 dp = new BigInteger[200][12]; 14 n = cin.nextInt(); 15 k = cin.nextInt(); 16 for(i = 0 ; i <=n ;i++) 17 for(j = 0 ; j < k ; j++) 18 dp[i][j] = BigInteger.valueOf(0); 19 for(i = 0; i < k ; i++) 20 { 21 dp[1][i] = BigInteger.valueOf(1); 22 } 23 for(i = 2 ; i <= n ; i++) 24 { 25 for(g = 0 ; g < k ; g++) 26 { 27 if(g!=0) 28 dp[i][g] = dp[i][g].add(dp[i-1][0]); 29 for(j = 1; j < k ; j++) 30 dp[i][g] = dp[i][g].add(dp[i-1][j]); 31 } 32 } 33 BigInteger ans; 34 ans = BigInteger.valueOf(0); 35 for(i = 1; i < k ; i++) 36 ans = ans.add(dp[n][i]); 37 System.out.println(ans); 38 } 39 40 }