D. Memory and Scores
 

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
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]中获取任意的一个分数

  AB起始分数分别为a,b

  问你最终A分数严格比B多的方案数

题解:

  设定dp[i][j]为第i轮 获得分数j的方案数

  这个可以进行滚动数组和前缀和优化

  最后枚举一个人的 分数 得到答案

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
using namespace std; #pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 5e5+, M = 1e2+, mod = 1e9+, inf = 2e9; int a,b,k,t;
LL sum[N], dp[][N];
int main() {
scanf("%d%d%d%d",&a,&b,&k,&t);
int now = ;
int last = now ^ ;
dp[last][] = ;
for(int i = ; i <= * k * t; ++i) sum[i] = ;
for(int i = ; i <= t; ++i) {
for(int j = ; j <= *k*t; ++j) {
if(j <= * k) dp[now][j] = sum[j];
else {
dp[now][j] = (( sum[j] - sum[j - *k - ] ) % mod + mod ) % mod;
}
}
sum[] = dp[now][];
for(int j = ; j <= * k * t; ++j)
sum[j] = ((sum[j-] + dp[now][j]) % mod + mod) % mod;
now^=;
}
LL ans = ;
for(int i = ; i <= * k * t; ++i) {
if(a + i - - b >= )ans = (ans + dp[now^][i] * sum[a + i - - b]%mod) % mod;
}
cout<<(ans+mod) % mod<<endl;
return ;
}

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

  1. Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划

    D. Memory and Scores 题目连接: http://codeforces.com/contest/712/problem/D Description Memory and his fr ...

  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 #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

随机推荐

  1. ios NSURLSession completeHandler默认调用quque

    注意 , [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSU ...

  2. SELinux的关闭与开启

    SELinux是美国国家安全局对于强制访问控制的实现,是NSA在Linux社区的帮助下开发的一种访问控制体系,所以SELinux可以看做是安全强化的Linux子系统,和防火墙有相似点,作用之一是保证计 ...

  3. python pexpect 学习与探索

    pexpect是python交互模块,有两种使用方法,一种是函数:run另外一种是spawn类 1.pexpect  module 安装 pexpect属于第三方的,所以需要安装, 目前的版本是 3. ...

  4. ABAP 承运路单

    *&---------------------------------------------------------------------* *& Report  ZSDR010 ...

  5. 最简单粗暴的http文件列表

    :]: port = ])else: port = 8000server_address = ('127.0.0.1', port)Handler.protocol_version = Protoco ...

  6. Python 开发轻量级爬虫04

    Python 开发轻量级爬虫 (imooc总结04--url管理器) 介绍抓取URL管理器 url管理器用来管理待抓取url集合和已抓取url集合. 这里有一个问题,遇到一个url,我们就抓取它的内容 ...

  7. java基础学习05(面向对象基础02)

    面向对象基础02 实现的目标 1.String类的使用2.掌握this关键字的使用3.掌握static关键字的使用4.了解内部类 String类 实例化String对象一个字符串就是一个String类 ...

  8. 安装Django,运行django-admin.py startproject 工程名,后不出现指定的工程解决办法!!

       第一次写博客,,,,, 在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startpr ...

  9. Hibernate双向一对多对象关系模型映射

    双向one-to-many 描述部门和岗位:一个部门有多个岗位 将单向的one-to-many 和many-to-one合并. 4.1双向的one-to-many数据库模型 create table ...

  10. app上传到app Store常见问题

    一.首先看一下提交界面出现的问题(能成功打包成.ipa) 产生问题的原因如下:由于工程中含有sub project,而sub project中有private或public的文件导致的.这样的应用往往 ...