A14073 | Planar Reflections
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$ . If a particle has decay age equal to $1$ , it will NOT produce a copy.
For example, if there are two planes and a particle is shot with decay age $3$ (towards the right), the process is as follows: (here, $D(x)$ refers to a single particle with decay age $x$ )
1. the first plane produces a $D(2)$ to the left and lets $D(3)$ continue on to the right;
2. the second plane produces a $D(2)$ to the left and lets $D(3)$ continue on to the right;
3. the first plane lets $D(2)$ continue on to the left and produces a $D(1)$ to the right;
4. the second plane lets $D(1)$ continue on to the right ( $D(1)$ cannot produce any copies).
In total, the final multiset $S$ of particles is $\{D(3), D(2), D(2), D(1)\}$ . (See notes for visual explanation of this test case.)
Gaurang is unable to cope up with the complexity of this situation when the number of planes is too large. Help Gaurang find the size of the multiset $S$ , given $n$ and $k$ .
Since the size of the multiset can be very large, you have to output it modulo $10^9+7$ .
Note: Particles can go back and forth between the planes without colliding with each other.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$ . If a particle has decay age equal to $1$ , it will NOT produce a copy.
For example, if there are two planes and a particle is shot with decay age $3$ (towards the right), the process is as follows: (here, $D(x)$ refers to a single particle with decay age $x$ )
1. the first plane produces a $D(2)$ to the left and lets $D(3)$ continue on to the right;
2. the second plane produces a $D(2)$ to the left and lets $D(3)$ continue on to the right;
3. the first plane lets $D(2)$ continue on to the left and produces a $D(1)$ to the right;
4. the second plane lets $D(1)$ continue on to the right ( $D(1)$ cannot produce any copies).
In total, the final multiset $S$ of particles is $\{D(3), D(2), D(2), D(1)\}$ . (See notes for visual explanation of this test case.)
Gaurang is unable to cope up with the complexity of this situation when the number of planes is too large. Help Gaurang find the size of the multiset $S$ , given $n$ and $k$ .
Since the size of the multiset can be very large, you have to output it modulo $10^9+7$ .
Note: Particles can go back and forth between the planes without colliding with each other.
输入格式
The first line of the input contains the number of test cases $t$ ( $1 \le t \le 100$ ). Then, $t$ lines follow, each containing two integers $n$ and $k$ ( $1 \le n, k \le 1000$ ).
Additionally, the sum of $n$ over all test cases will not exceed $1000$ , and the sum of $k$ over all test cases will not exceed $1000$ . All test cases in one test are different.
Additionally, the sum of $n$ over all test cases will not exceed $1000$ , and the sum of $k$ over all test cases will not exceed $1000$ . All test cases in one test are different.
输出格式
Output $t$ integers. The $i$ -th of them should be equal to the answer to the $i$ -th test case.
输入输出样例
输入 #1
4 2 3 2 2 3 1 1 3
输出 #1
4 3 1 2
输入 #2
3 1 1 1 500 500 250
输出 #2
1 2 257950823
Let us explain the first example with four test cases.
Test case 1: ( $n = 2$ , $k = 3$ ) is already explained in the problem statement.
See the below figure of this simulation. Each straight line with a different color represents the path of a different particle. As you can see, there are four distinct particles in the multiset. Note that the vertical spacing between reflected particles is for visual clarity only (as mentioned before, no two distinct particles collide with each other)
Test case 2: ( $n = 2$ , $k = 2$ ) is explained as follows:
1. the first plane produces a $D(1)$ to the left and lets $D(2)$ continue on to the right;
2. the second plane produces a $D(1)$ to the left and lets $D(2)$ continue on to the right;
3. the first plane lets $D(1)$ continue on to the left ( $D(1)$ cannot produce any copies).
Total size of multiset obtained $\{D(1), D(1), D(2)\}$ is equal to three.
Test case 3: ( $n = 3$ , $k = 1$ ), there are three planes, but decay age is only one. So no new copies are produced while the one particle passes through the planes. Hence, the answer is one.
Test case 4: ( $n = 1$ , $k = 3$ ) there is only one plane. The particle produces a new copy to the left. The multiset $\{D(2), D(3)\}$ is of size two.
Test case 1: ( $n = 2$ , $k = 3$ ) is already explained in the problem statement.
See the below figure of this simulation. Each straight line with a different color represents the path of a different particle. As you can see, there are four distinct particles in the multiset. Note that the vertical spacing between reflected particles is for visual clarity only (as mentioned before, no two distinct particles collide with each other)
Test case 2: ( $n = 2$ , $k = 2$ ) is explained as follows:
1. the first plane produces a $D(1)$ to the left and lets $D(2)$ continue on to the right;
2. the second plane produces a $D(1)$ to the left and lets $D(2)$ continue on to the right;
3. the first plane lets $D(1)$ continue on to the left ( $D(1)$ cannot produce any copies).
Total size of multiset obtained $\{D(1), D(1), D(2)\}$ is equal to three.
Test case 3: ( $n = 3$ , $k = 1$ ), there are three planes, but decay age is only one. So no new copies are produced while the one particle passes through the planes. Hence, the answer is one.
Test case 4: ( $n = 1$ , $k = 3$ ) there is only one plane. The particle produces a new copy to the left. The multiset $\{D(2), D(3)\}$ is of size two.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?