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 canvas显示文字(写上5个字,纪念我那刚刚逝去的爱情)

    <script type="text/javascript"> window.addEventListener('load',eventWindowLoaded,fal ...

  2. 【转】XMPP_3920_最靠谱的中文翻译文档

    CHENYILONG Blog XMPP_3920_最靠谱的中文翻译文档 Fullscreen © chenyilong. Powered by Postach.io Blog

  3. [转]LaTex常用数学符号整理

    转载自 http://blog.csdn.net/ying_xu/article/details/51240291 (自己保存方便查阅,侵删) 另一个网站 Markdown 添加 Latex 数学公式 ...

  4. Mybatis逆向工程——(十四)

    逆向工程可以快速将数据库的表生成JavaBean,同时生成对单标操作的Mapper.java与Mapper.xml,极大地提高了开发速度. 1.jar包

  5. [转]使用 mitmproxy + python 做拦截代理

    使用 mitmproxy + python 做拦截代理   本文是一个较为完整的 mitmproxy 教程,侧重于介绍如何开发拦截脚本,帮助读者能够快速得到一个自定义的代理工具. 本文假设读者有基本的 ...

  6. Centos 6.9 安装Rabbitmq

    一.安装Rabbitmq 首先安装编译工具 yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel Er ...

  7. 转:Vue-cli proxyTable 解决开发环境的跨域问题

    转:http://www.jianshu.com/p/95b2caf7e0da 和后端联调时总是会面对恼人的跨域问题,最近基于Vue开发项目时也遇到了这个问题,两边各自想了一堆办法,查了一堆资料,加了 ...

  8. Java基础88 数据库设计的三大范式

    数据库的设计原则:建议设计的表尽量遵守三大范式 1.第一范式 要求表的每个字段必须是不可分割的独立单元 Student表:    name       -- 违反了第一范式             张 ...

  9. window批处理——bat文件的编写

    BAT 批处理脚本 教程   第一章 批处理基础第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT或者CMD.这些命 ...

  10. 【转载】redis容灾策略

    版权声明:转载请注明出处 http://blog.csdn.net/irean_lau. https://blog.csdn.net/Irean_Lau/article/details/5136027 ...