CF1151F.Sonya and Informatics

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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 aa of length nn, consisting only of the numbers 00 and 11, and the number kk. Exactly kk times the following happens:

  • Two numbers ii and jj are chosen equiprobable such that (1≤i<j≤n1 \leq i \lt j \leq n).
  • The numbers in the ii and jj positions are swapped.

Sonya's task is to find the probability that after all the operations are completed, the aa 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 00 or it can be represented as PQ\dfrac{P}{Q}, where PP and QQ are coprime integers and Q≢0 (mod109+7)Q \not\equiv 0~\pmod {10^9+7}.

一位名叫索尼娅的女孩正在克雷姆兰德王国的科学中学学习。她的计算机科学老师(这门课是索尼娅最喜爱的科目!)为她设计了一道题目。

给定一个长度为 nn 的数组 aa,其中仅包含数字 00 和 11,以及一个整数 kk。接下来恰好执行 kk 次如下操作:

  • 等概率地随机选取两个下标 ii 和 jj,满足 1≤i<j≤n1 \leq i \lt j \leq n;
  • 交换数组中第 ii 个位置与第 jj 个位置上的数。

索尼娅的任务是:求经过全部 kk 次操作后,数组 aa 恰好按非递减顺序排列的概率。她向你寻求帮助,请你协助索尼娅解决这个问题。

可以证明:所求概率要么为 00,要么可表示为 PQ\dfrac{P}{Q} 的形式,其中 PP 与 QQ 互质,且 Q≢0 (mod109+7)Q \not\equiv 0~\pmod {10^9+7}。

输入格式

The first line contains two integers nn and kk (2≤n≤100,1≤k≤1092 \leq n \leq 100, 1 \leq k \leq 10^9) — the length of the array aa and the number of operations.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤10 \le a_i \le 1) — the description of the array aa.

第一行包含两个整数 nn 和 kk(2≤n≤1002 \leq n \leq 100,1≤k≤1091 \leq k \leq 10^9)——分别表示数组 aa 的长度和操作次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤10 \le a_i \le 1)——描述数组 aa。

输出格式

If the desired probability is 00, print 00, otherwise print the value P⋅Q−1P \cdot Q^{-1} (mod109+7)\pmod {10^9+7}, where PP and QQ are defined above.

如果所求概率为 00,则输出 00;否则输出 P⋅Q−1(mod109+7)P \cdot Q^{-1} \pmod {10^9+7},其中 PP 和 QQ 如上所定义。

输入输出样例

  • 输入#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 aa, after applying exactly two operations: (0,1,0)(0, 1, 0), (0,0,1)(0, 0, 1), (1,0,0)(1, 0, 0), (1,0,0)(1, 0, 0), (0,1,0)(0, 1, 0), (0,0,1)(0, 0, 1), (0,0,1)(0, 0, 1), (1,0,0)(1, 0, 0), (0,1,0)(0, 1, 0). Therefore, the answer is 39=13\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 00.

在第一个例子中,恰好执行两次操作后,最终数组 aa 的所有可能结果为:(0,1,0)(0, 1, 0)、(0,0,1)(0, 0, 1)、(1,0,0)(1, 0, 0)、(1,0,0)(1, 0, 0)、(0,1,0)(0, 1, 0)、(0,0,1)(0, 0, 1)、(0,0,1)(0, 0, 1)、(1,0,0)(1, 0, 0)、(0,1,0)(0, 1, 0)。因此,答案为 39=13\dfrac{3}{9}=\dfrac{1}{3}。

在第二个例子中,执行一次操作后,数组无法变为非递减顺序,因此答案为 00。

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

首页