Sheldon and Leonard

0

0 votes
Combinatorics, Dynamic Programming, Medium-Hard
Problem

Sheldon and Leonard are playing a game. Thay starts with score a and b respectively.

In a single turn, both of them picks a integer from [ - k , k ].

They always get a random integer at their turn.

The game has t turns.

Sheldon wants to know that in how many games he ends up with higher score then Leonard.

Since the answer can be very large, you should print it modulo 10^9 + 7.

Input -

  • The first line contains integers a, b, k, and t .

Output-

  • Print number of games (Sheldon ends up with higher score than Leonard) modulo 1000000007.

Constraints -

  • 1 ≤ a , b ≤ 100
  • 1 ≤ k ≤ 1000
  • 1 ≤ t ≤ 100
Time Limit: 2
Memory Limit: 512
Source Limit:
Explanation

Sheldon starts with 1 and Leonard starts with 2. As t=1 so both of them get only one chance to pick. Winning games for sheldon -

Leonard-------Sheldon

-2----------------- 0 or 1 or 2 (3)

-1-----------------1 or 2 (2)

0-----------------2 (1)

If Leonard pics 1 or 2 then Sheldon cannot win. So he can win in 3+2+1=6 games so answer is 6 modulo 1000000007 = 6.

Editor Image

?