Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2011 /round1a /diversity_number.html
wjomlex's picture
2011 Problems
df6dd12 verified
raw
history blame
1.77 kB
<p>Let's call a sequence of integers a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>N</sub> <i>almost monotonic</i> if first K elements are non-decreasing sequence and last N-K+1 elements are non-increasing sequence: a<sub>1</sub>&le;a<sub>2</sub>&le;...&le;a<sub>K</sub> and a<sub>K</sub>&ge;a<sub>K+1</sub>&ge;...&ge;a<sub>N</sub>.</p>
<p>The <i>diversity number</i> of a sequence a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>N</sub> is the number of possible sequences b<sub>1</sub>, b<sub>2</sub>,..., b<sub>N</sub> for which 0&le;b<sub>i</sub>&lt;a<sub>i</sub> and all of the numbers b<sub>1</sub>, b<sub>2</sub>,..., b<sub>N</sub> are different. The diversity number of an empty sequence is 1.</p>
<p>You need to find the sum of the diversity numbers of all almost monotonic subsequences of a sequence. Since this number can be very large, find it modulo 1,000,000,007. A subsequence is a sequence that can be obtained from another sequence by deleting some elements without changing the order of the remaining elements. Two sequences are considered different if their lengths differ or there is at least one position at which they differ.</p>
<h2>Input</h2>
<p>The first line of the input file consists of a single number <strong>T</strong>, the number of test cases. Each test case consists of a number <strong>M</strong>, the number of elements in a sequence, followed by <strong>M</strong> numbers <strong>n</strong>, elements of some sequence (note that this sequence is not necessarily <i>almost monotonic</i>). All tokens are whitespace-separated</p>
<h2>Constraints</h2>
<p>
<strong>T</strong> = 20<br/>
1 &le; <strong>M</strong>, <strong>n</strong> &le; 100
</p>
<h2>Output</h2>
<p>Output T lines, with the answer to each test case on a single line.</p>