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$ .
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$ .
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
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 — 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted