QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#16275. 合唱队

统计

为了在即将到来的晚会上有更好的演出效果,作为 AAA 合唱队负责人的小 A 需要将合唱队的人根据他们的身高排出一个队形。假定合唱队一共有 $N$ 个人,第 $i$ 个人的身高为 $H_i$ 毫米($1000 \le H_i \le 2000$),并且已知任何两个人的身高都不同。

假定最终排出的队形是 $N$ 个人站成一排。为了简化问题,小 A 想出了如下排队的方式:他让所有的人先按任意顺序站成一个初始队形,然后从左到右按以下原则依次将每个人插入最终排出的队形中:

  • 第一个人直接插入空的当前队形中。
  • 对从第二个人开始的每个人:
    • 如果他比前面那个人高($H$ 较大),那么将他插入当前队形的最右边。
    • 如果他比前面那个人矮($H$ 较小),那么将他插入当前队形的最左边。

当 $N$ 个人全部插入当前队形后便获得最终排出的队形。

例如,有 $6$ 个人站成一个初始队形,身高依次为 $1850、1900、1700、1650、1800$ 和 $1750$,那么小 A 会按以下步骤获得最终排出的队形:

  • $1850$
  • $1850, 1900$ 因为 $1900 > 1850$
  • $1700, 1850, 1900$ 因为 $1700 < 1900$
  • $1650, 1700, 1850, 1900$ 因为 $1650 < 1700$
  • $1650, 1700, 1850, 1900, 1800$ 因为 $1800 > 1650$
  • $1750, 1650, 1700, 1850, 1900, 1800$ 因为 $1750 < 1800$

因此,最终排出的队形是 $1750, 1650, 1700, 1850, 1900, 1800$。

小 A 心中有一个理想队形,他想知道从多少种初始队形出发能通过上述排队的方式获得他心中的理想队形作为最终排出的队形?

输入格式

输入第一行是一个正整数 $N$,表示总人数。输入文件第二行是用空格隔开的 $N$ 个正整数,从左到右表示小 A 心中的理想队形:$H_1, H_2, \dots, H_N$。

输入的数据保证 $1000 \le H_i \le 2000$ 且没有相同的 $H$ 值,其中 $30%$ 的数据满足 $1 \le N \le 100$,$100%$ 的数据满足 $1 \le N \le 1000$。

输出格式

输出仅包含一个数,表示从多少种初始队形出发能通过上述排队的方式获得输入文件中指定的小 A 心中的理想队形。因为满足条件的初始队形数可能很大,所以规定只要输出满足条件的初始队形数 $\bmod\ 19650827$ 的值。

样例数据 1

input.txt

4
1701 1702 1703 1704

output.txt

8

样例解释:$8$ 种初始队形分别为 $(1701, 1702, 1703, 1704)$、$(1704, 1703, 1702, 1701)$、$(1702, 1701, 1703, 1704)$、$(1703, 1702, 1701, 1704)$、$(1702, 1703, 1701, 1704)$、$(1702, 1703, 1704, 1701)$、$(1703, 1704, 1702, 1701)$、$(1703, 1702, 1704, 1701)$。

样例数据 2

input.txt

4
1704 1703 1702 1701

output.txt

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.