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. Qt ini配置文件读写

    #include <QSettings> void MainWindow::saveIni() { //如果ini文件不存在,创建新ini文件,存在赋值 QSettings *setIni ...

  2. php调用c/c++的一种方式

    php调用c/c++有很多方式,最常用的是通过tcp或者http去调用,通过发送请求去调用c/c++编写的cgi/fastcgi来实现,另外php还有一种直接执行外部应用程序的方式,这种方式会影响到系 ...

  3. We7 CMS研究

    我下载的we7 3.0是基于vs 2010的,官方网站也建议使用vs2010,但是我有追新的习惯,并相信vs 2013一定能够兼容vs2010的项目,于是在vs2013下打开解决方案并且全部升级,把目 ...

  4. Match:Keywords Search(AC自动机模板)(HDU 2222)

    多模匹配 题目大意:给定很多个字串A,B,C,D,E....,然后再给你目标串str字串,看目标串中出现多少个给定的字串. 经典AC自动机模板题,不多说. #include <iostream& ...

  5. OKhttp基本使用介绍

    MainActivity.class package com.example.administrator.okhttp3; import android.support.v7.app.AppCompa ...

  6. win7下安装openpyxl

    想使用python来操作Excel,看资料据说openpyxl非常好用,于是到https://pypi.python.org/pypi/openpyxl下载了安装包.下面就来说说安装步骤,也算是对自己 ...

  7. 【XLL API 函数】xlGetBinaryName

    用于返回由 xlDefineBinaryName 函数定义的名称数据句柄.定义的名称和工作簿一起保存,我们可以在任意时间访问这个名称. 原型 Excel12(xlGetBinaryName, LPXL ...

  8. python学习 小游戏

    基于python3.4 while循环 #!/usr/bin/python3 #-*- coding=utf-8 -*- import random import sys import os luck ...

  9. 在某公司时的java开发环境配置文档

    1 开发环境配置 1.1.  MyEclipse 配置 1.MyEclipse下载地址:\\server\共享文件\backup\MyEclipse9.0 2.修改工作空间编码为UTF-8,如下图 3 ...

  10. PHP安全编程:不要让不相关的人看到报错信息

    没有不会犯错的开发者,PHP的错误报告功 能可以协助你确认和定位这些错误,可以提供的这些错误的详细描述,但如果被恶意攻击者看到,这就不妙了.不能让大众看到报错信息,这一点很重要.做到这一 点很容易,只 ...