CF1845E.Boxes and Balls
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n boxes placed in a line. The boxes are numbered from 1 to n. 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 i and i+1 for all i from 1 to n−1 are considered adjacent to each other. Boxes 1 and n are not adjacent.
How many different arrangements of balls exist after exactly k 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+7.
有 n 个盒子排成一行,编号从 1 到 n。其中一些盒子中各含一个球,其余盒子为空。至少有一个盒子含球,且至少有一个盒子为空。
一次操作定义为:选择一个含球的盒子和一个与其相邻的空盒子,并将该球从含球盒子移动到空盒子中。对于所有 i(1≤i≤n−1),盒子 i 与盒子 i+1 被视为彼此相邻;而盒子 1 与盒子 n 不相邻。
恰好执行 k 次操作后,共能形成多少种不同的球分布方案?若存在至少一个盒子,在两种方案中一个含球、另一个不含球,则称这两种方案不同。
由于答案可能非常大,请输出其对 109+7 取模的结果。
输入格式
The first line contains two integers n and k (2≤n≤1500; 1≤k≤1500) — the number of boxes and the number of moves.
The second line contains n integers a1,a2,…,an (ai∈0,1) — 0 denotes an empty box and 1 denotes a box with a ball inside. There is at least one 0 and at least one 1.
第一行包含两个整数 n 和 k(2≤n≤1500;1≤k≤1500)—— 分别表示盒子的数量和移动次数。
第二行包含 n 个整数 a1,a2,…,an(ai∈{0,1})—— 其中 0 表示空盒子,1 表示装有球的盒子。至少存在一个 0 和一个 1。
输出格式
Print a single integer — the number of different arrangements of balls that can exist after exactly k moves are performed, modulo 109+7.
输出一个整数——恰好执行 k 次移动后,球可能存在的不同排列方式的数量,对 109+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 1 to box 2;
- 1 0 0 1 — obtained after moving the ball from box 3 to box 4;
- 1 1 0 0 — obtained after moving the ball from box 3 to box 2.
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 — 将球从第 1 个盒子移动到第 2 个盒子后得到;
- 1 0 0 1 — 将球从第 3 个盒子移动到第 4 个盒子后得到;
- 1 1 0 0 — 将球从第 3 个盒子移动到第 2 个盒子后得到。
在第二个例子中,存在以下可能的排列:
- 1 0 1 0 — 有三种方式得到该排列:只需将第一次操作逆向执行即可;
- 0 1 0 1 — 由第一次操作后的前两种排列之一得到。
输入解题思路,AI测评打分。不知道怎么写?