D. Memory and Scores

题目连接:

http://codeforces.com/contest/712/problem/D

Description

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 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.

Output

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

Sample Input

1 2 2 1

Sample Output

6

Hint

题意

有两个人在玩游戏,一开始分数分别为a和b,每一局,每个人可以获得分数[-k,k]之间,问你A胜过B的方案数有多少种

题解:

dp[i][j]表示第i轮之后,获得j分数的方案数。

显然这个只会和上一轮有关,所以可以滚动数组优化,又显然可以前缀和优化。

然后维护一下DP

最后再枚举A的分数,统计一下答案就好了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 4e5+7;
const int le = 2e5;
const int mod = 1e9+7;
long long a,b,k,t;
long long dp[2][maxn];
long long sum[maxn];
int now=0,pre=1;
int main()
{
scanf("%lld%lld%lld%lld",&a,&b,&k,&t);
dp[now][le]=1;
for(int i=1;i<=t;i++)
{
for(int j=1;j<maxn;j++)
{
sum[j]=dp[now][j]+sum[j-1];
sum[j]%=mod;
}
swap(now,pre);
memset(dp[now],0,sizeof(dp[now]));
for(int j=1;j<maxn;j++)
{
dp[now][j]+=sum[min(maxn-1LL,j+k)]-sum[max(0LL,j-k-1)];
dp[now][j]%=mod;
}
}
for(int j=1;j<maxn;j++)
{
sum[j]=dp[now][j]+sum[j-1];
sum[j]%=mod;
}
long long ans = 0;
for(int j=0;j<maxn;j++)
{
ans += sum[a+j-b-1]%mod*dp[now][j]%mod;
ans%=mod;
}
cout<<(ans+mod)%mod<<endl;
}

Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划的更多相关文章

  1. Codeforces Round #370 (Div. 2) D. Memory and Scores DP

    D. Memory and Scores   Memory and his friend Lexa are competing to get higher score in one popular c ...

  2. Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树

    E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...

  3. Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心

    地址:http://codeforces.com/problemset/problem/712/C 题目: C. Memory and De-Evolution time limit per test ...

  4. Codeforces Round #370 (Div. 2)B. Memory and Trident

    地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 se ...

  5. Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题

    C. Memory and De-Evolution 题目连接: http://codeforces.com/contest/712/problem/C Description Memory is n ...

  6. Codeforces Round #370 (Div. 2) B. Memory and Trident 水题

    B. Memory and Trident 题目连接: http://codeforces.com/contest/712/problem/B Description Memory is perfor ...

  7. Codeforces Round #370 (Div. 2) A. Memory and Crow 水题

    A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...

  8. Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)

    题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...

  9. Codeforces Round #556 (Div. 2) - D. Three Religions(动态规划)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 3000 mSec Problem Descripti ...

随机推荐

  1. HTML5 拖拽实现

    简介: 最早在网页中引入JavaScript拖放功能是IE4.当时,网页中只有两种对象可以拖放:图像和某些文本.拖放图像时,把鼠标放到图像上,按住鼠标不放就可以拖放它.拖放文本时,要先选中文本,然后可 ...

  2. ASP.NET MVC学习笔记-----Filter(2)

    接上篇ASP.NET MVC学习笔记-----Filter(1) Action Filter Action Filter可以基于任何目的使用,它需要实现IActionFilter接口: public ...

  3. html5 canvas多个图像旋转

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 转:我是否该放弃VB.Net?

    我是否该放弃VB.Net呢?这个问题一次次的出现在我的脑海里,而且这种想法越来越强烈.放弃VB.Net至少能让我的生活变得轻松些.如果你是个C#程序员,那拷贝粘贴代码会很容易,因为可以找到的例子代码如 ...

  5. CF359B Permutation (构造)

    CF359B Permutation \(solution:\) 作为一道构造题,这题也十分符合构造的一些通性----(找到一些规律,然后无脑循环). 构造一个长度为 \(2n\) 的排列 \(a\) ...

  6. Unity3d 常用代码

    //创建一个名为"Player"的游戏物体 //并给他添加刚体和立方体碰撞器. player=new GameObject("Player"); player. ...

  7. python3之模板pycurl探测web服务质量

    1.pycurl简介 pycURL是libcurl多协议文件传输库的python接口,与urllib模块类似,PycURL可用于从python程序中获取由URL标识的对象,功能很强大,libcurl速 ...

  8. Linux TTY驱动--Uart_driver底层【转】

    转自:http://blog.csdn.net/sharecode/article/details/9196591 版权声明:本文为博主原创文章,未经博主允许不得转载. Linux 中将串口驱动进行了 ...

  9. SOAP简单示例

    看了网上的几个文章,SOAP的示例布局都不清晰,不能马上入手,特意写个例子与大家分享,同时记录备用. 当前环境:VS2013 + WPF private void Button_Click(objec ...

  10. VUE之搭建脚手架

    原文转自http://blog.csdn.net/Shiyaru1314/article/details/54963027 目录(?)[-] 1 安装之前需要检查是否已经安装NodeJS的环境 安装文 ...