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. 给RelativeLayout设置背景,无效果bug解决

    drawable文件夹下面 tomyshop_selector.xml文件 <?xml version="1.0" encoding="utf-8"?&g ...

  2. CodeForces 340E Iahub and Permutations

    容斥原理,组合数. 找出有$cnt$个数字还有没放,那么总方案数就是$cnt!$. 总方案数里面包含了正确的和非正确的,我们需要将非正确的删去. 先删去$1$个数字$a[i]=i$的情况,发现会多删, ...

  3. JUnit——(二)注解

    1. 两种错误:Error和Failure Error是代码错误 @Test publicvoid testAdd() { int z=new T().add(5,3); assertEquals(8 ...

  4. Comparer<T> IComparer<T> IComparable<T>

    Comparer<T>.Default Property Comparer<T>.Default doesn't use your FooComparer class. It ...

  5. hibernate主键generator属性介绍

    increment(递增) 用于为long, short或者int类型生成唯一标识.只有在没有其他进程往同一张表中插入数据时才能使用. 在集群下不要使用. identity (标识)对DB2,MySQ ...

  6. Scala学习---映射和元祖

    1.设置一个映射,其中包含你想要的一些装备,以及他们的价格.然后构建另一个映射,采用同一组键,但在价格上打9折. scala> val map = Map("a"->1 ...

  7. sql语句的学习(1)

    一.创建表 CREATE TABLE `student` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) DEFAULT NULL COMMENT '姓名', ` ...

  8. Win7安装mysql数据库、修改默认密码

    学习和使用myslq数据库半年时间,mysql对于每一个开发人员都不会陌生.今天对电脑重装系统,为了方面测试在个人PC上安装了mysql数据库.以一下是整个安装过程. 一.下载mysql 1.首先需要 ...

  9. ASP_Login

    ===第一种============================================================================================== ...

  10. linux下串口通信与管理

    linux下的串口与windows有一些区别,下面将介绍一下linux下串口通信管理 查看是否支持USB串口: #lsmod | grep usbserial 如果没有信息:sudo apt-get ...