$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. Mysql中实现多表关联查询更新操作

    今天一下要记录一下才行了,每次都要去网上查找方法,每次都难找得要命 Mysql在更新某些字段的数据时,有时候会依据其他表的数据进行更新,需要通过关联后对不同的行更新不同的值,传统的update set ...

  2. 通过google的inurl:backupdata*dede_admin获取账号密码

    简要描述:很简单,通过google可找出备份路径. 详细说明:http://www.google.com.hk/search?q=inurl:backupdata*dede_admin&hl= ...

  3. [转]Introduction to Core Bluetooth: Building a Heart Rate Monitor

    ref:http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor The C ...

  4. AsyncTasLoader不进行加载操作的原因及解决方法

    使用AsyncTaskLoader加载数据.但是LoadInBackground却不会被回调.这是什么情况?我要怎么解决这个问题?如果你和我一样有这样的疑问.你可以移步至我的blog的这篇文章找到答案 ...

  5. iphone手机用wireshark抓包

    ios连上电脑 查看udid. 启动虚拟接口 rvictl -s 7e65eeaa55a1e43dbdfb44a02f9871f1f304043e 打开mac权限 sudo chmod 644 /de ...

  6. Mahout之(三)相似性度量

    User CF 和 Item CF 都依赖于相似度的计算,因为只有通过衡量用户之间或物品之间的相似度,才能找到用户的“邻居”,才能完成推荐.上文简单的介绍了相似性的计算,但不完全,下面就对常用的相似度 ...

  7. 记录下自己写的gulp打包脚本

    var c = { rootPath: 'src',//项目文件夹 outputPath: 'output',//文件编译后的输出目录 revPath: 'manifest',//rev映射文件目录 ...

  8. ADS的go to命令

    我们有时候在一个函数右键没有看到“go to”选项,这是因为没有Make,要先Make之后才能使用go to 命令

  9. javaSocket与C通信

    前段时间写了个web端与C服务端之间的通信不过用的是短连接 非堵塞的方式,一直想使用长连接,使tomcat启动的时候就和C服务端进行通信,但是一直没找到方法希望je的朋友能给点思路.先来看我现在的具体 ...

  10. c数据结构学习随笔

    #include <stdio.h> #include <stdlib.h> #include "PublicDS.h" #include<Windo ...