CF1845E.Boxes and Balls

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn boxes placed in a line. The boxes are numbered from 11 to nn. Some boxes contain one ball inside of them, the rest are empty. At least one box contains a ball and at least one box is empty.

In one move, you have to choose a box with a ball inside and an adjacent empty box and move the ball from one box into another. Boxes ii and i+1i+1 for all ii from 11 to n−1n-1 are considered adjacent to each other. Boxes 11 and nn are not adjacent.

How many different arrangements of balls exist after exactly kk moves are performed? Two arrangements are considered different if there is at least one such box that it contains a ball in one of them and doesn't contain a ball in the other one.

Since the answer might be pretty large, print its remainder modulo 109+710^9+7.

有 nn 个盒子排成一行,编号从 11 到 nn。其中一些盒子中各含一个球,其余盒子为空。至少有一个盒子含球,且至少有一个盒子为空。

一次操作定义为:选择一个含球的盒子和一个与其相邻的空盒子,并将该球从含球盒子移动到空盒子中。对于所有 ii(1≤i≤n−11 \le i \le n-1),盒子 ii 与盒子 i+1i+1 被视为彼此相邻;而盒子 11 与盒子 nn 不相邻。

恰好执行 kk 次操作后,共能形成多少种不同的球分布方案?若存在至少一个盒子,在两种方案中一个含球、另一个不含球,则称这两种方案不同。

由于答案可能非常大,请输出其对 109+710^9+7 取模的结果。

输入格式

The first line contains two integers nn and kk (2≤n≤15002 \le n \le 1500; 1≤k≤15001 \le k \le 1500) — the number of boxes and the number of moves.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (ai∈0,1a_i \in {0, 1}) — 00 denotes an empty box and 11 denotes a box with a ball inside. There is at least one 00 and at least one 11.

第一行包含两个整数 nn 和 kk(2≤n≤15002 \le n \le 1500;1≤k≤15001 \le k \le 1500)—— 分别表示盒子的数量和移动次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(ai∈{0,1}a_i \in \{0, 1\})—— 其中 00 表示空盒子,11 表示装有球的盒子。至少存在一个 00 和一个 11。

输出格式

Print a single integer — the number of different arrangements of balls that can exist after exactly kk moves are performed, modulo 109+710^9+7.

输出一个整数——恰好执行 kk 次移动后,球可能存在的不同排列方式的数量,对 109+710^9+7 取模。

输入输出样例

  • 输入#1

    4 1
    1 0 1 0

    输出#1

    3
  • 输入#2

    4 2
    1 0 1 0

    输出#2

    2
  • 输入#3

    10 6
    1 0 0 1 0 0 0 1 1 1

    输出#3

    69

说明/提示

In the first example, there are the following possible arrangements:

  • 0 1 1 0 — obtained after moving the ball from box 11 to box 22;
  • 1 0 0 1 — obtained after moving the ball from box 33 to box 44;
  • 1 1 0 0 — obtained after moving the ball from box 33 to box 22.

In the second example, there are the following possible arrangements:

  • 1 0 1 0 — three ways to obtain that: just reverse the operation performed during the first move;
  • 0 1 0 1 — obtained from either of the first two arrangements after the first move.

在第一个例子中,存在以下可能的排列:

  • 0 1 1 0 — 将球从第 11 个盒子移动到第 22 个盒子后得到;
  • 1 0 0 1 — 将球从第 33 个盒子移动到第 44 个盒子后得到;
  • 1 1 0 0 — 将球从第 33 个盒子移动到第 22 个盒子后得到。

在第二个例子中,存在以下可能的排列:

  • 1 0 1 0 — 有三种方式得到该排列:只需将第一次操作逆向执行即可;
  • 0 1 0 1 — 由第一次操作后的前两种排列之一得到。

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

首页