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. 从后台调用前台js

    引用: using System.Web.UI; ScriptManager.RegisterClientScriptBlock(this, GetType(), "Js", &q ...

  2. iOS UIBezierPath类 介绍

      使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和 ...

  3. js的兼容技巧

    javascript原生代码中经常会遇到各式各样浏览器不兼容的问题,浏览器真是倔强,解决浏览器的兼容是前端猿们的一大难题 为了避免在工作中遇到这些简单的问题.节约开发时间,在这里总结一些常用的浏览器兼 ...

  4. 【实验室笔记】serialport的readline()方法

    在最近的小项目中,单片机中断优先级的问题,串口发送到上位机的数据有时会出现发送的数据被中断打断的问题. 于是,在上位机机上就容易出现错误,原来读取的方法是read()的方法,反复修改发送数据的格式依然 ...

  5. 批处理改hosts

    @echo off color 0F @attrib -r "%windir%\system32\drivers\etc\hosts" @echo ######测试配置 beg & ...

  6. Mybatis的传参

    最近重新温习了遍Mybatis ,觉得还是汇总一下比较好,方便自己以后的快速开发 最终要的一点事,自己写的话,记忆更加深刻: 首先自己先写了个静态块,防止代码冗余: private static Sq ...

  7. windows10安装composer并解决和xdebug的冲突

    环境:windows10,php7,php安装目录C:\php\,php目录已加入windows的PATH. 1.下载composer,在Windows下最简单的办法是下载composer.phar并 ...

  8. IP地址接口小结

    1 百度http://api.map.baidu.com/location/ip?ak=F454f8a5efe5e577997931cc01de3974&ip=58.67.143.169 {& ...

  9. sql 关于dblink和多条update、insert事务回滚写法

    在存储过程的编写中难免会遇到调用同库他人的proc和跨库调用proc,还有一个proc中有多条对多表进行写入和修改的语句.那么就会用到tran. 如果我们在不写try的情况下就要对每个insert,u ...

  10. 项目管理-SVN服务器的搭建

    Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下载地址: http:// ...