D. Memory and Scores
Memory and his friend Lexa is 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 the current scores. The game has exactly T turns. Memory and Lexa, however, is not good at the this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such, he ends with a strictly higher score than Lexa. Both games is considered to being different if in at least one turn at least one player gets different score. There is (2k + 1)2t games in total. Since the answer can be very large and you should print it modulo 9 + 7. Please solve the problem for Memory.
Input
The first and only line of input contains the four integers a, b, K, and t< /c7> (1≤ a, b ≤100, 1≤ k ≤1000, 1≤ t ≤100)-the amount Memo Ry and Lexa start with, the number K, and the number of turns respectively.
Output
Print the number of possible games satisfying the conditions modulo 1 007 (9 + 7) in one line.
Examples
input
1 2 2 1
Output
6
Note
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 is3 + 2 + 1 = 6 possible games in which Memory wins.
Test instructions
A, b Two people play T-wheel game
No one can get any score from [-k,k] per round of games
AB starting points are a, B, respectively
Ask you the final a score is more rigorous than the number of programs in B
Exercises
Set DP[I][J] The number of schemes to obtain fractional J for the first round
This can be done with scrolling arrays and prefixes and optimizations
Finally enumerate a person's score to get the answer
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<Set>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineLS i<<1#defineRS ls | 1#defineMid ((LL+RR) >>1)#definePII pair<int,int>#defineMP Make_pairtypedefLong LongLL;Const Long LongINF =1e18;Const DoublePi = ACOs (-1.0);Const intN = 5e5+Ten, M = 1e2+ One, mod = 1e9+7, INF =2e9;inta,b,k,t; LL Sum[n], dp[2][n];intMain () {scanf ("%d%d%d%d",&a,&b,&k,&t); intnow =1; intLast = now ^1; dp[last][0] =1; for(inti =0; I <=2* k * t; ++i) Sum[i] =1; for(inti =1; I <= t; ++i) { for(intj =0; J <=2*k*t; ++j) {if(J <=2* k) Dp[now][j] =Sum[j]; Else{Dp[now][j]= ((Sum[j]-sum[j-2*k-1]% mod + MoD)%MoD; }} sum[0] = dp[now][0]; for(intj =1; J <=4* k * t; ++j) Sum[j]= ((sum[j-1] + dp[now][j])% mod + MoD)%MoD; now^=1; } LL ans=0; for(inti =0; I <=2* k * t; ++i) {if(A + I-1-B >=0) ans = (ans + dp[now^1][i] * sum[a + i-1-B]%mod)%MoD; } cout<< (ans+mod)% mod<<Endl; return 0;}
Codeforces Round #370 (Div. 2) D. Memory and Scores DP