PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000020. Đếm dãy con tăng đúng K phần tử (INCSEQ - Increasing Subsequences)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm dãy con tăng đúng K phần tử (INCSEQ - Increasing Subsequences)
INCSEQ - Increasing Subsequences
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers, choose exactly indices such that . Count all such choices of positions, even if two different choices yield identical values. Print the count modulo .
Input
The first line contains integers . It is followed by exactly integers in order, possibly on separate lines.
Output
Print one integer: the number of strictly increasing subsequences of length exactly , modulo .
Subtasks
- Subtask 1 (20 points): ; and ; for every .
- Subtask 2 (30 points): ; and ; for every .
- Subtask 3 (50 points): ; and ; for every .
Examples
Input
4 3
1
2
2
10
Output
2
Explanation
A length-three increasing subsequence must begin with and end with . The middle element can be the at position or the at position . Thus the two index triples and are counted, giving .