TopcoderArchive
Archive11 Apr 2019
Cognizance - Insomnia

GreaterThanAll

Problem statement, definition, constraints, and public examples.

Problem Statement

Given a sequence A = (a1, a2, ..., an) (where a[i] >= 1 are integers), of length n, we define the Peak_Set as
Peak_Set(A) = { a[i] : a[i] > a[j] for all j < i }

For example, for the sequence A = {2, 1, 5, 6, 3, 3, 2, 8, 10, 4}, Peak_Set(A) = {2, 5, 6, 8, 10}.

For a given integers N and K, you need to count the number of Sequences 'X' of length N with Peak_Set(X) = {1, 2, 3,..., K}, modulo (109 + 7).

Definition

Class:
GreaterThanAll
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int n, int k)
(be sure your method is public)

Constraints

  • The number of elements of the sequence, N ranges from 1 to 106, inclusive.
  • The value of K is between 1 and N.

Examples

  1. 3
    2
    Returns: 3
    The only possible sequences are "112", "121" and "122" whose Peak_Set is {1, 2}.
  2. 762476
    157929
    Returns: 441862509
Back to all problems