#P4879. Riding in a Lift

    ID: 2517 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>动态规划基础算法前缀和CodeForces

Riding in a Lift

Riding in a Lift

题面翻译

nn 层楼,开始在 aa 层。可以上下楼,设开始在 xx 层,走到了 yy 层,则这次上下楼必须满足 xy<xb\left|x-y\right|<\left|x-b\right|,并且不能到达 bb 层。
求上下楼 kk 次的不同走法数量,对 109+710^9+7 取模。

题目描述

Imagine that you are in a building that has exactly n n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 1 to n n . Now you're on the floor number a a . You are very bored, so you want to take the lift. Floor number b b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k k consecutive trips in the lift.

Let us suppose that at the moment you are on the floor number x x (initially, you were on floor a a ). For another trip between floors you choose some floor with number y y ( yx y≠x ) and the lift travels to this floor. As you cannot visit floor b b with the secret lab, you decided that the distance from the current floor x x to the chosen y y must be strictly less than the distance from the current floor x x to floor b b with the secret lab. Formally, it means that the following inequation must fulfill: xy<xb |x-y|<|x-b| . After the lift successfully transports you to floor y y , you write down number y y 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 k k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 1000000007 ( 109+7 10^{9}+7 ).

输入格式

The first line of the input contains four space-separated integers n n , a a , b b , k k ( 2<=n<=5000 2<=n<=5000 , 1<=k<=5000 1<=k<=5000 , 1<=a,b<=n 1<=a,b<=n , ab a≠b ).

输出格式

Print a single integer — the remainder after dividing the sought number of sequences by 1000000007 1000000007 ( 109+7 10^{9}+7 ).

样例 #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 n n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 1 to n n . Now you're on the floor number a a . You are very bored, so you want to take the lift. Floor number b b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k k consecutive trips in the lift.

Let us suppose that at the moment you are on the floor number x x (initially, you were on floor a a ). For another trip between floors you choose some floor with number y y ( yx y≠x ) and the lift travels to this floor. As you cannot visit floor b b with the secret lab, you decided that the distance from the current floor x x to the chosen y y must be strictly less than the distance from the current floor x x to floor b b with the secret lab. Formally, it means that the following inequation must fulfill: xy<xb |x-y|<|x-b| . After the lift successfully transports you to floor y y , you write down number y y 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 k k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 1000000007 ( 109+7 10^{9}+7 ).