CF1874E.Jellyfish and Hack
NOI/NOI+/CTSC
通过率:0%
时间限制:8.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
It is well known that quick sort works by randomly selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. But Jellyfish thinks that choosing a random element is just a waste of time, so she always chooses the first element to be the pivot. The time her code needs to run can be calculated by the following pseudocode:
function fun(A)
if A.length > 0
let L[1 ... L.length] and R[1 ... R.length] be new arrays
L.length = R.length = 0
for i = 2 to A.length
if A[i] < A[1]
L.length = L.length + 1
L[L.length] = A[i]
else
R.length = R.length + 1
R[R.length] = A[i]
return A.length + fun(L) + fun(R)
else
return 0
Now you want to show her that her code is slow. When the function fun(A) is greater than or equal to lim, her code will get Time Limit Exceeded. You want to know how many distinct permutations P of [1,2,…,n] satisfies fun(P)≥lim. Because the answer may be large, you will only need to find the answer modulo 109+7.
众所周知,快速排序通过从数组中随机选择一个“基准”(pivot)元素,并根据其余元素是否小于或大于该基准,将它们划分为两个子数组。但水母(Jellyfish)认为随机选取元素纯粹是浪费时间,因此她总是选择第一个元素作为基准。她的代码运行所需的时间可通过以下伪代码计算:
function fun(A)
if A.length > 0
let L[1 ... L.length] and R[1 ... R.length] be new arrays
L.length = R.length = 0
for i = 2 to A.length
if A[i] < A[1]
L.length = L.length + 1
L[L.length] = A[i]
else
R.length = R.length + 1
R[R.length] = A[i]
return A.length + fun(L) + fun(R)
else
return 0
现在你想向她证明她的代码很慢。当函数 fun(A) 的值大于等于 lim 时,她的代码将出现“超时”(Time Limit Exceeded)。你想知道:有多少个 [1,2,…,n] 的不同排列 P 满足 fun(P)≥lim?由于答案可能很大,你只需输出结果对 109+7 取模的值。
输入格式
The only line of the input contains two integers n and lim (1≤n≤200, 1≤lim≤109).
输入仅包含一行,其中有两个整数 n 和 lim(1≤n≤200,1≤lim≤109)。
输出格式
Output the number of different permutations that satisfy the condition modulo 109+7.
输出满足条件的不同排列的数量,对 109+7 取模。
输入输出样例
输入#1
4 10
输出#1
8
输入#2
8 32
输出#2
1280
说明/提示
In the first example, P=[1,4,2,3] satisfies the condition, because: fun([1,4,2,3])=4+fun([4,2,3])=7+fun([2,3])=9+fun([3])=10
Do remember to output the answer modulo 109+7.
在第一个例子中,P=[1,4,2,3] 满足条件,因为:fun([1,4,2,3])=4+fun([4,2,3])=7+fun([2,3])=9+fun([3])=10
请注意,输出答案时需对 109+7 取模。
输入解题思路,AI测评打分。不知道怎么写?