$dp$,前缀和。

记$dp[i][j]$表示$i$轮结束之后,两人差值为$j$的方案数。

转移很容易想到,但是转移的复杂度是$O(2*k)$的,需要优化,观察一下可以发现可以用过前缀和来优化。

我把所有的数组全部开成$long$ $long$超时了,全改成$int$就$AC$了......

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int B=;
const int mod=1e9+;
const int maxn=;
int dp[][maxn];int a,b,t,k;
int c[maxn],d[maxn],e[maxn],f[maxn]; int main()
{
scanf("%d%d%d%d",&a,&b,&k,&t); int rr=*k; for(int j=;j<=;j++)
{
int tmp=j-B;
if(tmp<-rr||tmp>rr) continue;
dp[][j]=(rr-(abs(tmp)-)+mod)%mod;
} for(int i=;i<=t;i++)
{
d[]=; c[]=dp[i-][];
for(int j=;j<=;j++)
{
c[j]=(c[j-]+dp[i-][j])%mod;
d[j]=(d[j-]+c[j-])%mod;
} f[]=; e[]=dp[i-][];
for(int j=-;j>=;j--)
{
e[j]=(e[j+]+dp[i-][j])%mod;
f[j]=(f[j+]+e[j+])%mod;
} for(int j=;j<=;j++)
{
int pp=j-B; if(pp<-rr*i) continue; if(j-<) continue; int tmp=c[j-];
if(j-rr>) tmp=(tmp-c[j-rr-]+mod)%mod; LL gh=((LL)tmp*rr)%mod;
dp[i][j]=(int)gh; tmp=d[j-];
if(j-rr>)
{
tmp=(tmp-d[j-rr-]+mod)%mod;
LL df=((LL)c[j-rr-]*rr%mod);
tmp=(tmp-(int)df+mod)%mod;
} LL jk=(e[j+]-e[j+rr+]+mod)%mod;
jk=jk*rr%mod; dp[i][j]=(((dp[i][j]-tmp+mod)%mod)+(int)jk)%mod; tmp=(f[j+]-f[j+rr+]+mod)%mod;
LL fg=(LL)e[j+rr+]*rr%mod; tmp=(tmp-(int)fg+mod)%mod; dp[i][j]=(dp[i][j]-tmp+mod)%mod;
dp[i][j]=(dp[i][j]+(LL)(rr+)*dp[i-][j]%mod)%mod; }
for(int j=B+;j<=;j++) dp[i][j]=dp[i][*B-j];
} if(k==&&t==) dp[t][*B]=dp[t][]=; LL ans=;
for(int i=b-a+;i<=;i++) ans=(ans+dp[t][i+B])%mod;
printf("%lld\n",ans); return ;
}

CodeForces 712D Memory and Scores的更多相关文章

  1. [CodeForces - 712D]Memory and Scores (DP 或者 生成函数)

    题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高.  ( ...

  2. 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 ...

  3. 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 ...

  4. Memory and Scores

    Memory and Scores 题目链接:http://codeforces.com/contest/712/problem/D dp 因为每轮Memory和Lexa能取的都在[-k,k],也就是 ...

  5. [Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列)

    [Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列) 题面 两个人玩游戏,共进行t轮,每人每轮从[-k,k]中选出一个数字,将其加到自己的总分中.已 ...

  6. 【26.87%】【codeforces 712D】Memory and Scores

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  7. Codeforces 712 D. Memory and Scores (DP+滚动数组+前缀和优化)

    题目链接:http://codeforces.com/contest/712/problem/D A初始有一个分数a,B初始有一个分数b,有t轮比赛,每次比赛都可以取[-k, k]之间的数,问你最后A ...

  8. codeforces 712B. Memory and Trident

    题目链接:http://codeforces.com/problemset/problem/712/B 题目大意: 给出一个字符串(由'U''D''L''R'),分别是向上.向下.向左.向右一个单位, ...

  9. codeforces 712A. Memory and Crow

    题目链接:http://codeforces.com/problemset/problem/712/A 题目大意: 给你一个数字系列,求其满足条件的一个序列. 条件为: ai = bi - bi +  ...

随机推荐

  1. asp.net mvc4 运用 paypal sdk实现支付

    1.https://developer.paypal.com/ 注册账号,并且申请一个app,获得 client id,secret等数据   2.点击页面中"Sandbox Account ...

  2. tornado\ioloop.py单例

    @staticmethod def instance(): """Returns a global `IOLoop` instance. Most application ...

  3. windbg Symbol file path

    SOS是一个调试器扩展,用于调试.NET应用程序.它提供了一组非常丰富的命令,这些命令使开发人员可以对CLR进行深入分析,并且有助于找出应用程序中各种复杂错误的原因.   由于SOS能够提供CLR内部 ...

  4. Quartz表达式生成器

    Java版的Quartz表达式生成器,同时适用于Quartz.net(免费下载) Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2 ...

  5. 线性回归,logistic回归和一般回归

    1 摘要 本报告是在学习斯坦福大学机器学习课程前四节加上配套的讲义后的总结与认识.前四节主要讲述了回归问题,回归属于有监督学习中的一种方法.该方法的核心思想是从连续型统计数据中得到数学模型,然后将该数 ...

  6. .net下将富文本编辑器文本原样读入word文档

    关键词:富文本编辑器  生成word  样式 为了解决标题中提出的问题,首选需要了解,在.net环境下读取数据库中的内容动态生成word至少有2种方式,[方式一]一种方式是在项目中添加引用,例如在“添 ...

  7. HttpStack及其实现类

    HttpStack及其实现类 前两篇已经对网络请求流程已经梳理了个大概,这次我们着重看一下HttpStack和它的其实现类.我们之前在Network篇讲过它仅有一个实现类,而今天我们讲的HttpSta ...

  8. python打包成window可执行程序

    python程序可以通过python hello.py执行,但是需要安装python的解释器,并配置环境变量,打包成exe程序之后可以直接执行. 使用setup工具和py2exe可以做到这一点. 最简 ...

  9. 持续集成环境(Hudson)搭建

    持续集成环境(Hudson)搭建 这是在公司写的,公司要求用英文,我也没时间翻译了.还请见谅! Hudson是个非常强大持续集成工具,配合svn,maven,sonar,redmine工具就更加完美了 ...

  10. GIT 版本控制命令学习

    一   基本命令 1.$ git init 要对现有的某个项目开始用 Git 管理,只需到此项目所在的目录,执行: 2.$ git status 检查当前文件状态 3.git add命令 功能1:可以 ...