El Dorado
InterviewTime limit1sMemory limit128 MB
Count the increasing subsequences of length exactly k in a sequence of n distinct numbers, for several test cases.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array, Combinatorics
- Solved
- No attempts yet
Problem
A casino game shows a sequence of numbers on its screen, and the player must guess how many increasing subsequences of length the sequence contains.
A subsequence of a sequence is any chosen by indices . Such a subsequence is increasing if holds for every .
Given the sequence shown on the screen, write a program that counts the number of increasing subsequences of length .
Input
The input consists of several test cases. The first line of each test case contains two integers and (). The second line contains the sequence , whose elements are pairwise distinct ().
The last line of the input contains two zeros and must not be processed.
Output
For each test case, print the number of increasing subsequences of length , one per line. This value fits within the range of a 64-bit integer.