D. Memory and Scores
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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.

Input

The first and only line of input contains the four integers abk, 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.

Output

Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.

Examples
input
1 2 2 1
output
6
input
1 1 1 2
output
31
input
2 12 3 1
output
0
Note

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 are3 + 2 + 1 = 6 possible games in which Memory wins.

题意:两个人最开始有a,b两个初始数,玩t轮游戏,每个人都随机从【-k,k】之间获得一个数加进他们的分数,问最后问最开始是a的人比另外一个大的方案数%1e9就可以;

题解:f[i]表示得分为i的情况数(每轮更新),然后用sum[]来维护f[i]的前缀和,状态转移方程就是f[j]=(sum[loc]-sum[j-k-1]+mod)%mod;(loc=min(j+k,r-k)注意边界)

然后就是数组下表不能小于0;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
double eps=1e-;
const int maxn=4e5+;
int zero=2e5+;
const int mod=1e9+;
using namespace std;
int f[maxn],sum[maxn];
int a,b,k,t;
int main()
{
scanf("%d %d %d %d",&a,&b,&k,&t);
int l=zero-k,r=zero+k;
//if(a==1&&b==100&&k==1000&&t==100)
for(int i=l;i<=r;i++)
{
f[i]=;
sum[i]=sum[i-]+f[i];
}
for(int i=;i<=t;i++)
{
l=zero-k*i,r=zero+k*i;
for(int j=l;j<=r;j++)
{
int loc=min(j+k,r-k);
f[j]=(sum[loc]-sum[j-k-]+mod)%mod;
}
for(int j=l;j<=r;j++)
{
sum[j]=(sum[j-]+f[j])%mod;
}
}
l=zero-t*k; r=zero+t*k;
int ans=;
for(int i=l;i<=r;i++)
{
int loc=min(i+a-b-,r);
ans=(ans+((ll)sum[loc]*f[i])%mod)%mod;
}
printf("%d\n",ans); }

http://codeforces.com/problemset/problem/712/D的更多相关文章

  1. http://codeforces.com/problemset/problem/594/A

    A. Warrior and Archer time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. codeforces.com/problemset/problem/213/C

    虽然一开始就觉得从右下角左上角直接dp2次是不行的,后面还是这么写了WA了 两次最大的并不一定是最大的,这个虽然一眼就能看出,第一次可能会影响第二次让第二次太小. 这是原因. 5 4 32 1 18 ...

  3. http://codeforces.com/problemset/problem/847/E

    E. Packmen time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  4. http://codeforces.com/problemset/problem/545/D

    D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  5. codeforces 340C Tourist Problem

    link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...

  6. codeforces B. Routine Problem 解题报告

    题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...

  7. Codeforces 527D Clique Problem

    http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...

  8. Codeforces 706C - Hard problem - [DP]

    题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整 ...

  9. Codeforces 1096D - Easy Problem - [DP]

    题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符 ...

随机推荐

  1. hashMap遍历方式

    package Ch17; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java ...

  2. Python学习日志_2017/09/08

    今天早晨学习了<Head First :HTML and CSS>:学习了两个章节,感觉从基础学习特别的踏实,能看懂的同时踏踏实实的锻炼了基础的能力.我个人认为无论哪个行业,最重要的永远是 ...

  3. mysql创建字段非空NOT NULL的好处

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt338 很多表都包含可为 NULL (空值) 的列,即使应用程序井不需要保存 ...

  4. java锁机制

    2.4 锁机制        临界区是指,使用同一个锁控制的同一段代码区或多段代码区之间,在同一时间内最多只能有一个线程在执行操作.这个概念与传统的临界区有略微的差别,这里不想强调这些概念上的差别,临 ...

  5. !JS实战之随机像素图

    JavaScript实例分享之----画随机像素图.随机像素图(作者自己取得名字)指的是一张图片上每一个像素的颜色都是随机的.此时应该能联想到这幅图多么眼花缭乱,好吧,我们用JS来实现它的原因是JS很 ...

  6. PHP中如何调试?

    比如有个数组: $arr = array('A' => 'bobi','B' => 'hehe'); echo $arr;                //Array   只打印出了变量 ...

  7. JS学习四(BOM DOM)

    BOM                Screen对象 console.log(window.width);//屏幕宽度 console.log(window.height);//屏幕高度 conso ...

  8. 【Beta阶段】第三次scrum meeting

    Coding/OSChina 地址 1. 会议内容 学号 主要负责的方向 昨日任务 昨日任务完成进度 接下去要做 99 PM 打包上传团队代码 100% 查找适合的素材模块,和105一起把手势功能连接 ...

  9. 201521123050 《Java程序设计》第5周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 答:不 ...

  10. Python[小甲鱼006常用操作符]

    1.操作符 下面有一些需要注意的操作符 >>>3 ** 2 9 上面这个代表着平方   即  3的平方 >>>3 ** 5 243                  ...