A12492 | Sonya and Informatics
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array $a$ of length $n$ , consisting only of the numbers $0$ and $1$ , and the number $k$ . Exactly $k$ times the following happens:
- Two numbers $i$ and $j$ are chosen equiprobable such that ( $1 \leq i < j \leq n$ ).
- The numbers in the $i$ and $j$ positions are swapped.
Sonya's task is to find the probability that after all the operations are completed, the $a$ array will be sorted in non-decreasing order. She turned to you for help. Help Sonya solve this problem.
It can be shown that the desired probability is either $0$ or it can be represented as $\dfrac{P}{Q}$ , where $P$ and $Q$ are coprime integers and $Q \not\equiv 0~\pmod {10^9+7}$ .
Given an array $a$ of length $n$ , consisting only of the numbers $0$ and $1$ , and the number $k$ . Exactly $k$ times the following happens:
- Two numbers $i$ and $j$ are chosen equiprobable such that ( $1 \leq i < j \leq n$ ).
- The numbers in the $i$ and $j$ positions are swapped.
Sonya's task is to find the probability that after all the operations are completed, the $a$ array will be sorted in non-decreasing order. She turned to you for help. Help Sonya solve this problem.
It can be shown that the desired probability is either $0$ or it can be represented as $\dfrac{P}{Q}$ , where $P$ and $Q$ are coprime integers and $Q \not\equiv 0~\pmod {10^9+7}$ .
输入格式
The first line contains two integers $n$ and $k$ ( $2 \leq n \leq 100, 1 \leq k \leq 10^9$ ) — the length of the array $a$ and the number of operations.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 1$ ) — the description of the array $a$ .
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 1$ ) — the description of the array $a$ .
输出格式
If the desired probability is $0$ , print $0$ , otherwise print the value $P \cdot Q^{-1}$ $\pmod {10^9+7}$ , where $P$ and $Q$ are defined above.
输入输出样例
输入 #1
3 2 0 1 0
输出 #1
333333336
输入 #2
5 1 1 1 1 0 0
输出 #2
0
输入 #3
6 4 1 0 0 1 1 0
输出 #3
968493834
In the first example, all possible variants of the final array $a$ , after applying exactly two operations: $(0, 1, 0)$ , $(0, 0, 1)$ , $(1, 0, 0)$ , $(1, 0, 0)$ , $(0, 1, 0)$ , $(0, 0, 1)$ , $(0, 0, 1)$ , $(1, 0, 0)$ , $(0, 1, 0)$ . Therefore, the answer is $\dfrac{3}{9}=\dfrac{1}{3}$ .
In the second example, the array will not be sorted in non-decreasing order after one operation, therefore the answer is $0$ .
In the second example, the array will not be sorted in non-decreasing order after one operation, therefore the answer is $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted