$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. [整理]Breakpoint on arbitrary selector

    基本解释了最近在调试时遇到的一些疑问,接下来就是找解决方法了. //-- Begin: 1 T __mh_execute_header 0000000005614542-000000 OPT radr ...

  2. python学习之路三(文件读写)

    # -*- coding: utf-8 -* ''' Created on 2013-7-29 @author: lixingle ''' import os #引入操作文件和目录的函数包 impor ...

  3. JQ与AJAX 省市区三级联动下拉框

    用于初学者学习基本的联动下拉框,废话不多说,见代码 首先看控制器里的3个下拉框对应代码: public ActionResult GetProvinceList() { ProvinceReposit ...

  4. No CurrentSessionContext configured 异常解决

    Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext conf ...

  5. Redis协议详解

    smark Beetle可靠.高性能的.Net Socket Tcp通讯组件 支持flash amf3,protobuf,Silverlight,windows phone Redis协议详解 由于前 ...

  6. 一个意想不到的Javascript内存泄漏

    原文:http://point.davidglasser.net/2013/06/27/surprising-javascript-memory-leak.html 本周我在Meter的同事追踪到了一 ...

  7. 案例研究:Web应用出现间歇性的SqlException

    案例研究:Web应用出现间歇性的SqlException 2013-07-29 14:36 by 微软互联网开发支持, 231 阅读, 3 评论, 收藏, 编辑 最近有客户找到我,说他们生产环境的事件 ...

  8. shell脚本获取随机数random

    用C提供的取随机数的方法srand和rand, 前者是给后者设置随机数种子seed. ; srand(seed); // time(NULL) 通常使用时间做种子 rnd_num = rand(); ...

  9. Ubuntu apt-get: Package has no installation candidate

    今天在安装软件的时候出现了Package has no installation candidate的问题,如: #  apt-get install <packagename>Readi ...

  10. oracle存储过程异常捕获

    在oracle中捕获异常,通过 //sql执行 exception when others then dbms_output.putline('exception'); 其中others表示捕获未命名 ...