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. HDU 4403 A very hard Aoshu problem

    暴力$dfs$. 先看数据范围,字符串最长只有$15$,也就是说枚举每个字符后面是否放置“$+$”号的复杂度为${2^{15}}$. 每次枚举到一种情况,看哪些位置能放“$=$”号,每个位置都试一下, ...

  2. VIP站长大会(北京站)常见问题解答

    功能支持问题 1. react能否和MIP结合使用,如果暂时不能以后是否有考虑?是否会和其他 js 框架(比如angular )结合? 目前暂无计划支持. 2. MIP页是否支持自定义cookie?实 ...

  3. hadoop,yarn和vcpu资源配置

    Hadoop  YARN同时支持内存和CPU两种资源的调度(默认只支持内存,如果想进一步调度CPU,需要自己进行一些配置),本文将介绍YARN是如何对这些资源进行调度和隔离的. 在YARN中,资源管理 ...

  4. 5、范围标签<fieldset></fieldset>

    <fieldset style="border:0;border:1px solid red;"> <legend style="background- ...

  5. 【git】TurtoiseGit使用手册

    A,创建本地分支 操作:Create Branch ->输入本地分支名 -> OK B,创建本地分支和远程分支的映射 操作: 1,拉取远程分支:Fetch -> 选中Arbitray ...

  6. 7、Objective-C中的各种遍历(迭代)方式

    一.使用for循环 要遍历字典.数组或者是集合,for循环是最简单也用的比较多的方法,示例如下: //普通的for循环遍历 -(void)iteratorWithFor { //////////处理数 ...

  7. linux内存管理(repost)

    一 为什么需要使用虚拟内存 大家都知道,进程需要使用的代码和数据都放在内存中,比放在外存中要快很多.问题是内存空间太小了,不能满足进程的需求,而且现在都是多进程,情况更加糟糕.所以提出了虚拟内存,使得 ...

  8. 101个linq例子

    FirstOrDefault - Simple public void Linq61() { int[] numbers = { }; int firstNumOrDefault = numbers. ...

  9. SQLServer性能优化

    http://www.cnblogs.com/studyzy/archive/2008/11/24/1339772.html

  10. my_query()的引号注意

    $sql="insert into lianxi values(null,'$usename','$email',$sex,$age,'$chusheng','$guanji')" ...