Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.
The first and only line of input contains the four integers a, b, k, and t (1 ≤ a, b ≤ 100, 1 ≤ k ≤ 1000, 1 ≤ t ≤ 100) — the amount Memory and Lexa start with, the number k, and the number of turns respectively.
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
1 2 2 1
6
1 1 1 2
31
2 12 3 1
0
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins.
题意:两个人玩游戏,初始分分别为a,b,一共玩t轮,每轮两人分别从[-K,K]中选一个数加到自己的分数中,问最后第一个人比第二个人分高的情况数。
分析:这题的关键点在t轮每次选两个数可以看待成每次选一个数玩2*t轮,分析到这一点就可以直接维护前缀和DP了。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <unordered_map>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MOD 1000000007
#define MAXN 201105
using namespace std;
typedef long long ll;
int a,b,k,t;
int pre[205][402215];
int main()
{
scanf("%d%d%d%d",&a,&b,&k,&t);
for(int i = b-a;i <= MAXN;i++) pre[0][i+MAXN] = 1;
for(int i = 1;i <= 2*t;i++)
for(int j = -2*t*k-100;j <= 2*t*k+100;j++)
pre[i][j+MAXN] = ((pre[i-1][j+k+MAXN] - pre[i-1][j-k-1+MAXN] + pre[i][j+MAXN-1]) % MOD + MOD) % MOD;
printf("%d\n",pre[2*t][MAXN-1]);
}