• ural 1013. K-based Numbers. Version 3(动态规划)


    1013. K-based Numbers. Version 3

    Let’s consider K-based numbers, containing exactly N digits. We define a number to be valid if its K-based notation doesn’t contain two successive zeros. For example:
    • 1010230 is a valid 7-digit number;
    • 1000198 is not a valid number;
    • 0001235 is not a 7-digit number, it is a 4-digit number.
    Given two numbers N and K, you are to calculate an amount of valid K based numbers, containing N digits.
    You may assume that 2 ≤ K ≤ 10; N ≥ 2; N + K ≤ 1800.

    Input

    The numbers N and K in decimal notation separated by the line break.

    Output

    The result in decimal notation.

    Sample

    inputoutput
    2
    10
    
    90
    

    题意:

    思路:和1009、1012一样;这三个题只是更改了数据范围;1012和本题用到了高精度运算;

     1 import java.util.Scanner;
     2 import java.util.regex.Pattern;
     3 import java.lang.Math;
     4 import java.math.BigInteger;
     5 
     6 
     7 
     8 public class t1 {
     9     public static void main(String[] args) {
    10         Scanner ks=new Scanner(System.in);
    11         BigInteger a,b,c,d,e;
    12         a=new BigInteger("0");
    13         b=new BigInteger("0");
    14         c=new BigInteger("1");
    15         d=new BigInteger("0");
    16         e=new BigInteger("0");
    17         int n,k;
    18         n=ks.nextInt();
    19         k=ks.nextInt();
    20         int i;
    21         for(i=1;i<k;i++)
    22         {
    23             d=d.add(c);//调出进制数减1;
    24         }
    25         b=b.add(d);
    26         for(i=2;i<=n;i++)
    27         {
    28             e=b.multiply(c);//保存变量b的值;
    29             b=b.add(a);//更新b的值;
    30             b=b.multiply(d);//更新b的值
    31             a=e.multiply(c);//跟新a的值;
    32         }
    33         b=a.add(b);
    34         System.out.println(b.toString());
    35     }
    36 }
    View Code
  • 相关阅读:
    黑马程序员文件流的写入
    SCOPE_IDENTITY()代替 @@IDENTITY
    Asp.net 常用的正则表达式汇集
    jquery工作小笔记:jquery获取页面上控件的值
    将公历转换成农历的类_C#
    数字人民币(RMB)转化为大写字母
    常用JS判断各种格式,以及替换函数等
    iis预览.net发布的网站时遇到的莫名问题:无资源行。
    sql 自动补位
    switchhost引发的问题
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3304251.html
Copyright © 2020-2023  润新知