#P4879. Riding in a Lift
Riding in a Lift
Riding in a Lift
题面翻译
层楼,开始在 层。可以上下楼,设开始在 层,走到了 层,则这次上下楼必须满足 ,并且不能到达 层。
求上下楼 次的不同走法数量,对 取模。
题目描述
Imagine that you are in a building that has exactly floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from to . Now you're on the floor number . You are very bored, so you want to take the lift. Floor number has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make consecutive trips in the lift.
Let us suppose that at the moment you are on the floor number (initially, you were on floor ). For another trip between floors you choose some floor with number ( ) and the lift travels to this floor. As you cannot visit floor with the secret lab, you decided that the distance from the current floor to the chosen must be strictly less than the distance from the current floor to floor with the secret lab. Formally, it means that the following inequation must fulfill: . After the lift successfully transports you to floor , you write down number in your notepad.
Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by ( ).
输入格式
The first line of the input contains four space-separated integers , , , ( , , , ).
输出格式
Print a single integer — the remainder after dividing the sought number of sequences by ( ).
样例 #1
样例输入 #1
5 2 4 1
样例输出 #1
2
样例 #2
样例输入 #2
5 2 4 2
样例输出 #2
2
样例 #3
样例输入 #3
5 3 4 1
样例输出 #3
0
提示
Imagine that you are in a building that has exactly floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from to . Now you're on the floor number . You are very bored, so you want to take the lift. Floor number has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make consecutive trips in the lift.
Let us suppose that at the moment you are on the floor number (initially, you were on floor ). For another trip between floors you choose some floor with number ( ) and the lift travels to this floor. As you cannot visit floor with the secret lab, you decided that the distance from the current floor to the chosen must be strictly less than the distance from the current floor to floor with the secret lab. Formally, it means that the following inequation must fulfill: . After the lift successfully transports you to floor , you write down number in your notepad.
Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by ( ).