PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000019. Đếm mọi dãy con tăng nghiêm ngặt (Increasing Subsequence II)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm mọi dãy con tăng nghiêm ngặt (Increasing Subsequence II)
Increasing Subsequence II
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array, form a subsequence by choosing one or more positions while preserving their order. Count all nonempty strictly increasing subsequences. Different selections of positions count separately even if their selected values coincide. Print the count modulo .
Input
The first line contains . The next line contains integers (duplicates are allowed).
Output
Print one integer: the number of nonempty strictly increasing subsequences, modulo .
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
3
2 1 3
Output
5
Explanation
There are three one-element subsequences: , , , and two increasing two-element subsequences: and . The full three-element sequence is not increasing because . The total is .