zoukankan      html  css  js  c++  java
  • URAL1012. K-based Numbers. Version 2

    链接

    考查大数 正好拿来学习下JAVA JAVA好高端。。

     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 }
    View Code
  • 相关阅读:
    257. Binary Tree Paths
    324. Wiggle Sort II
    315. Count of Smaller Numbers After Self
    350. Intersection of Two Arrays II
    295. Find Median from Data Stream
    289. Game of Life
    287. Find the Duplicate Number
    279. Perfect Squares
    384. Shuffle an Array
    E
  • 原文地址:https://www.cnblogs.com/shangyu/p/3300669.html
Copyright © 2011-2022 走看看