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

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-7;
const int maxn=4e5+2000;
int zero=2e5+2005;
const int mod=1e9+7;
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]=1;
        sum[i]=sum[i-1]+f[i];
    }
    for(int i=2;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-1]+mod)%mod;
         }
         for(int j=l;j<=r;j++)
         {
             sum[j]=(sum[j-1]+f[j])%mod;
         }
    }
     l=zero-t*k; r=zero+t*k;
     int ans=0;
    for(int i=l;i<=r;i++)
    {
        int loc=min(i+a-b-1,r);
        ans=(ans+((ll)sum[loc]*f[i])%mod)%mod;
    }
    printf("%d\n",ans); 

} 
时间: 2024-07-29 04:18:43

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

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

D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For e

CodeForces 687A NP-Hard Problem

Portal:http://codeforces.com/problemset/problem/687/A 二分图染色 好模板题 有SPJ 值得注意的是,因为C++的奇妙的运算机制 若在vector变量x.size()=0,则x.size()-1会溢出(此处坑了我3h) 这不禁让我想起了文明2里的甘地 1 #include<iostream> 2 #include<algorithm> 3 #include<set> 4 #include<cstdio> 5

codeforces 706C Hard problem DP(动态规划)问题

题目链接:http://codeforces.com/problemset/problem/706/C 题目大意:  给定n个字符串, 每个字符串可以颠倒前后位置(第一个字母到最后一个,第二个字母到倒数第二位) 每次颠倒需要花费ci的力气, 要求将所给的n个字符串用最小力气按字典序排列, 输出力气值, 如果无法按字典序排列, 则输出-1 数据范围:2?≤?n?≤?100?000 . ci (0?≤?ci?≤?1e9) 所有字符串总长度不会超过1000000. 解题思路: 这是一道DP题, dp[

codeforces Round 286# problem A. Mr. Kitayuta&#39;s Gift

Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For

codeforces 17A Noldbach problem

Noldbach problem time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 c

Codeforces Round#413 Problem A - C

[写在前面感(乱)叹(七)人(八)生(糟)的话] 本想借此机会一口气玩到蓝名,结果,A题写炸(少判了一种情况),C题写炸(辜负了我5分钟狂敲出来的线段树),结果又掉Rating...内心好绝望... Problem#A Carrot Cakes vjudge链接[here] (偷个懒,cf链接就不给了) 题目大意是说,烤面包,给出一段时间内可以考的面包数,建第二个炉子的时间,需要达到的面包数,问建炉子是否合理. 玄学 & 智商题,可能是因为我智商不够,所以在我决定休息的时候被hank掉了...

Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the settl

Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The most popular one is the

Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit