A16216 | Jellyfish and Hack
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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:
```
<pre class="verbatim"><br></br>function fun(A)<br></br> if A.length > 0<br></br> let L[1 ... L.length] and R[1 ... R.length] be new arrays<br></br> L.length = R.length = 0<br></br> for i = 2 to A.length<br></br> if A[i] < A[1]<br></br> L.length = L.length + 1<br></br> L[L.length] = A[i]<br></br> else<br></br> R.length = R.length + 1<br></br> R[R.length] = A[i]<br></br> return A.length + fun(L) + fun(R)<br></br> else<br></br> return 0<br></br>
```
Now you want to show her that her code is slow. When the function $\mathrm{fun(A)}$ is greater than or equal to $lim$ , her code will get $\text{Time Limit Exceeded}$ . You want to know how many distinct permutations $P$ of $[1, 2, \dots, n]$ satisfies $\mathrm{fun(P)} \geq lim$ . Because the answer may be large, you will only need to find the answer modulo $10^9+7$ .
```
<pre class="verbatim"><br></br>function fun(A)<br></br> if A.length > 0<br></br> let L[1 ... L.length] and R[1 ... R.length] be new arrays<br></br> L.length = R.length = 0<br></br> for i = 2 to A.length<br></br> if A[i] < A[1]<br></br> L.length = L.length + 1<br></br> L[L.length] = A[i]<br></br> else<br></br> R.length = R.length + 1<br></br> R[R.length] = A[i]<br></br> return A.length + fun(L) + fun(R)<br></br> else<br></br> return 0<br></br>
```
Now you want to show her that her code is slow. When the function $\mathrm{fun(A)}$ is greater than or equal to $lim$ , her code will get $\text{Time Limit Exceeded}$ . You want to know how many distinct permutations $P$ of $[1, 2, \dots, n]$ satisfies $\mathrm{fun(P)} \geq lim$ . Because the answer may be large, you will only need to find the answer modulo $10^9+7$ .
输入格式
The only line of the input contains two integers $n$ and $lim$ ( $1 \leq n \leq 200$ , $1 \leq lim \leq 10^9$ ).
输出格式
Output the number of different permutations that satisfy the condition modulo $10^9+7$ .
输入输出样例
输入 #1
4 10
输出 #1
8
输入 #2
8 32
输出 #2
1280
In the first example, $P = [1, 4, 2, 3]$ satisfies the condition, because: $\mathrm{fun(4, [1, 4, 2, 3]) = 4 + fun(3, [4, 2, 3]) = 7 + fun(2, [2, 3]) = 9 + fun(1, [3]) = 10}$
Do remember to output the answer modulo $10^9+7$ .
Do remember to output the answer modulo $10^9+7$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted