Connection Status:
Competition Arena > LittleElephantAndArray
SRM 592 · 2013-06-25 · by Witaliy · Brute Force, Dynamic Programming
Class Name: LittleElephantAndArray
Return Type: int
Method Name: getNumber
Arg Types: (long long, int)
Problem Statement

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.

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
0)
1
9
Returns: 1
1)
10
2
Returns: 15
2)
4747774
1
Returns: 8369
3)
6878542150015
74
Returns: 977836619
4)
1000000000000000
100
Returns: 22435455

Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LittleElephantAndArray with a public method int getNumber(long long A, int N) · 41 test cases · 2 s / 256 MB per case

Submitting as anonymous