• Memory and Scores


    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.

    分析:dp[i][j]表示第i轮获得分数为j的方案数;

       计数时维护前缀和即可;

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define Lson L, mid, rt<<1
    #define Rson mid+1, R, rt<<1|1
    const int maxn=5e5+10;
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    int n,m,k,t;
    ll dp[2][maxn],sum[maxn],a,b;
    int main()
    {
        int i,j;
        scanf("%lld%lld%d%d",&a,&b,&k,&t);
        dp[0][0]=1;
        int now=1;
        rep(i,0,2*k*t)sum[i]=1;
        rep(i,1,t)
        {
            rep(j,0,2*k*t)
            {
                if(j<=2*k)dp[now][j]=sum[j];
                else dp[now][j]=(sum[j]-sum[j-2*k-1]+mod)%mod;
            }
            sum[0]=dp[now][0];
            rep(j,1,2*k*t+100)
            {
                sum[j]=(sum[j-1]+dp[now][j])%mod;
            }
            now^=1;
        }
        ll ans=0;
        rep(i,0,2*k*t)
        {
            if(i+a-b-1>=0)ans=(ans+dp[now^1][i]*sum[i+a-b-1]%mod)%mod;
        }
        printf("%lld
    ",ans);
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    IntelliJ IDEA 2019.3 激活码
    TortoiseGit创建分支合并
    Lombok常用注解
    springboot项目打包发布流程
    liunx下部署jar包
    TortoiseGit配置SSH
    springboot单元测试 Failed to load ApplicationContext
    IDEA SpringBoot项目 Maven Reading Maven projects
    Spring的xml配置文件标签导入问题
    CentOS7 root用户、普通用户 vim与vi的切换
  • 原文地址:https://www.cnblogs.com/dyzll/p/5925909.html
Copyright © 2020-2023  润新知