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

input output
2
10
90

题意:

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

 import java.util.Scanner;
import java.util.regex.Pattern;
import java.lang.Math;
import java.math.BigInteger; public class t1 {
public static void main(String[] args) {
Scanner ks=new Scanner(System.in);
BigInteger a,b,c,d,e;
a=new BigInteger("0");
b=new BigInteger("0");
c=new BigInteger("1");
d=new BigInteger("0");
e=new BigInteger("0");
int n,k;
n=ks.nextInt();
k=ks.nextInt();
int i;
for(i=1;i<k;i++)
{
d=d.add(c);//调出进制数减1;
}
b=b.add(d);
for(i=2;i<=n;i++)
{
e=b.multiply(c);//保存变量b的值;
b=b.add(a);//更新b的值;
b=b.multiply(d);//更新b的值
a=e.multiply(c);//跟新a的值;
}
b=a.add(b);
System.out.println(b.toString());
}
}

ural 1013. K-based Numbers. Version 3(动态规划)的更多相关文章

  1. POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)

    POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...

  2. 九章面试题:Find first K frequency numbers 解题报告

    Find first K frequency numbers /* * Input: int[] A = {1, 1, 2, 3, 4, 5, 2}; k = 3 * return the highe ...

  3. K Closest Numbers In Sorted Array

    Given a target number, a non-negative integer k and an integer array A sorted in ascending order, fi ...

  4. 544. Top k Largest Numbers【medium】

    Given an integer array, find the top k largest numbers in it.   Example Given [3,10,1000,-99,4,100] ...

  5. Top k Largest Numbers

    Given an integer array, find the top k largest numbers in it. Example Given [3,10,1000,-99,4,100] an ...

  6. 【leetcode】1296. Divide Array in Sets of K Consecutive Numbers

    题目如下: Given an array of integers nums and a positive integer k, find whether it's possible to divide ...

  7. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  8. ural 1012. K-based Numbers. Version 2(大数dp)

    和1009相同,只是n达到了180位,可以模拟大数加和大数乘,这里用的java中的大数. import java.math.BigInteger; import java.util.Scanner; ...

  9. 61. 从1到n,共有n个数字,每个数字只出现一次。从中随机拿走一个数字x,请给出最快的方法,找到这个数字。如果随机拿走k(k>=2)个数字呢?[find k missing numbers from 1 to n]

    [本文链接] http://www.cnblogs.com/hellogiser/p/find-k-missing-numbers-from-1-to-n.html  [题目] 从1到n,共有n个数字 ...

随机推荐

  1. ES 6 : 数组的扩展

    1.Array.from() Array.from方法用于将两类对象转为真正的数组:类似数组的对象和可遍历(iterable)对象. 下面是一个类似数组的对象,Array.from将它转为真正的数组. ...

  2. 读取HttpWebResponse流的两种方法及注意的问题

    1.  获取流 HttpWebRequest request= (HttpWebRequest)WebRequest.Create(uri); //构建http request     request ...

  3. 通过一个表的id同时查询多个表的数据

    'select c.字段名,x.字段名 as 改为新的显示名,x.字段名 from 表名1 b,表名2 c,表名3 x where b.字段id=' . $id . ' and b.`字段id`=c. ...

  4. 建立tcl文件

  5. Jquery 获取上传文件大小

    <input type="file" id="file1" /> <script> var size = $("#file1& ...

  6. ubuntu14.04下安装ice3.5.1

    ubuntu 14.04下是可以通过下面这条指令安装ice3.5的 sudo apt-get install libzeroc-ice35-dev 1. 从这里下载ice源文件 主要包括两部分:ice ...

  7. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  8. Linux 网络性能tuning向导

    本文的目的不完全在于提供调优信息,而是在于告诉读者了解Linux kernel如何处理数据包,从而能够在 自己的实践中发挥Linux 内核协议栈最大的性能 The NIC ring buffer 接收 ...

  9. Linux命令学习-useradd和usermod

    1.useradd 创建用户的时候创建家目录 useradd luyun :创建用户luyun,系统会自动创建/home/luyun 目录,此目录便是luyun的家目录. useradd -d /ho ...

  10. redis7--hash set的操作

    数据类型Hash(1)介绍hash数据类型存储的数据与mysql数据库中存储的一条记录极为相似Redis本身就类似于Hash的存储结构,分为key-value键值对,实际上它的Hash数据就好像是在R ...