题库练习 Boxes and Balls
← 上一题 下一题 →

A15994 | Boxes and Balls

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 $10^9+7$ .

输入格式

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

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $a_i \in \{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$ .

输出格式

Print a single integer — the number of different arrangements of balls that can exist after exactly $k$ moves are performed, modulo $10^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
C++ 编辑器
输入
输出