TopcoderArchiveVisit Topcoder
SRM25 Jun 2013
SRM 592

LittleElephantAndArray

Problem statement, definition, constraints, and public examples.

Problem Statement

Little Elephant from the Zoo of Lviv likes sequences of integers.

You are given a long A and an int N. Little Elephant has the sequence S = (A, A+1, ..., A+N). Little Elephant now wants to erase some digits from some of the numbers. He may erase multiple digits from the same number, but he will not erase any of the numbers completely. After erasing some digits from a number the gaps disappear. For example, by erasing the middle digit of the number 147 Little Elephant obtains the number 17 (and not two separate numbers 1 and 7).

It is allowed for some number to contain leading zeroes after erasings. For example, from the number 1047 Little Elephant may create, among other possibilities, the number 047 or the number 47. These are two different ways of erasing. They are both allowed and the numbers they produce have the same value.

Two ways of erasing the digits are considered different if there is some position in some element of S that was erased in one of the cases and was not erased in the other one. For example, if S = (11, 12), there are two different ways to change it to (1, 2). (In one of them we erase the first and in the other we erase the second digit of the number 11.)

After erasing the digits, Little Elephant wants to obtain a non-decreasing sequence. Let R be the number of different ways to do that. Return R modulo 1,000,000,007.

Definition

Class:
LittleElephantAndArray
Method:
getNumber
Parameters:
long, int
Returns:
int
Method signature:
int getNumber(long A, int N)
(be sure your method is public)

Constraints

  • A will be between 1 and 1,000,000,000,000,000 (10^15), inclusive.
  • N will be between 0 and 100, inclusive.

Examples

  1. 1
    9
    Returns: 1
  2. 10
    2
    Returns: 15
  3. 4747774
    1
    Returns: 8369
  4. 6878542150015
    74
    Returns: 977836619
Back to all problems