CF1436C.Binary Search

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number xx in an array. For an array aa indexed from zero, and an integer xx the pseudocode of the algorithm is as follows:

Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).

Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find xx!

Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size nn such that the algorithm finds xx in them. A permutation of size nn is an array consisting of nn distinct integers between 11 and nn in arbitrary order.

Help Andrey and find the number of permutations of size nn which contain xx at position pospos and for which the given implementation of the binary search algorithm finds xx (returns true). As the result may be extremely large, print the remainder of its division by 109+710^9+7.

安德烈认为自己是一位真正成功的开发者,但实际上直到最近他才了解到二分查找算法。在阅读了一些资料后,安德烈明白了该算法可以快速在数组中查找某个数 xx。对于一个从下标 0 开始索引的数组 aa 和一个整数 xx,该算法的伪代码如下:

注意:数组元素的下标从 0 开始,且除法为整数除法(向下取整)。

安德烈读到,该算法仅在数组已排序时才有效。然而,他发现这一说法并不正确,因为显然存在一些未排序的数组,使得该算法仍能成功找到 xx!

安德烈打算给这本书的作者写一封信,但在动笔之前,他必须先考虑所有大小为 nn 的排列,使得该算法能在其中找到 xx。大小为 nn 的排列是指由 11 到 nn 这 nn 个互不相同的整数组成、顺序任意的数组。

请帮助安德烈,求出满足以下条件的大小为 nn 的排列的个数:其中 xx 位于位置 pospos,且上述二分查找算法能成功找到 xx(即返回 true)。由于结果可能极大,请输出其对 109+710^9+7 取模后的余数。

输入格式

The only line of input contains integers nn, xx and pospos (1≤x≤n≤10001 \le x \le n \le 1000, 0≤pos≤n−10 \le pos \le n - 1) — the required length of the permutation, the number to search, and the required position of that number, respectively.

输入仅有一行,包含整数 nn、xx 和 pospos(1≤x≤n≤10001 \le x \le n \le 1000,0≤pos≤n−10 \le pos \le n - 1),分别表示所要求的排列长度、待搜索的数字,以及该数字所需位于的位置。

输出格式

Print a single number — the remainder of the division of the number of valid permutations by 109+710^9+7.

输出一个整数——有效排列的数目对 109+710^9+7 取模的余数。

输入输出样例

  • 输入#1

    4 1 2

    输出#1

    6
  • 输入#2

    123 42 24

    输出#2

    824071958

说明/提示

All possible permutations in the first test case: (2,3,1,4)(2, 3, 1, 4), (2,4,1,3)(2, 4, 1, 3), (3,2,1,4)(3, 2, 1, 4), (3,4,1,2)(3, 4, 1, 2), (4,2,1,3)(4, 2, 1, 3), (4,3,1,2)(4, 3, 1, 2).

第一个测试用例中所有可能的排列:(2,3,1,4)(2, 3, 1, 4)、(2,4,1,3)(2, 4, 1, 3)、(3,2,1,4)(3, 2, 1, 4)、(3,4,1,2)(3, 4, 1, 2)、(4,2,1,3)(4, 2, 1, 3)、(4,3,1,2)(4, 3, 1, 2)。

输入解题思路,AI测评打分。不知道怎么写?

首页