$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. 在 Ubuntu 12.04 上通过 Tomcat 部署 Solr 4

    http://www.oschina.net/question/12_71342 可行

  2. 2013.7.19 STL库的学习

    STL提供了一组表示容器,迭代器,函数对象和算法的模板. 容器是一个与数组类似的单元,可以存储若干个值.容器是同质的,即存储的值的类型一样. 算法是完成特定任务的处方. 迭代器能够用来遍历容器的对象, ...

  3. (转)NoSQL——Redis在win7下安装配置的学习一

    NoSQL——Redis在win7下安装配置的学习一   有些也是从网上看来的 1.下载安装 Redis它没有windows的官方版本,但是又非官方的版本,到官网上去下载相应的版本,我的电脑是win7 ...

  4. CentOS上搭建java WEB开发环境Tomcat+MySQL+JDK

    对于初学者来说,想在linux系统上搭建一个java web服务器,不知道什么方案可行, 这篇文章主要是告诉这些基础和概念相对薄弱的同学,这样搭建是可行的,大体上没问 题的,出问题也是细节问题.所以此 ...

  5. Github官方app分析——用户身份验证模块

    这篇文章记述的是我对Giuhub官方app的用户身份验证模块的分析. Giuhub的官方app虽然是一个非常小众的程序,但是从程序的设计的角度看,这是一个非常优秀的项目.对于其用户身份验证模块,给我留 ...

  6. Win32_Battery class

    wmi的Win32_Battery类实现 其中EstimatedChargeRemaining属性返回剩余电量的百分比,EstimatedRunTime属性返回剩余时间(分钟) 其他属性参考http: ...

  7. struts整合spring整合hibernate

    1, web.xml中配置spring监听类 <listener> <listener-class>org.springframework.web.context.Contex ...

  8. LinqToXml高级用法介绍

    LinqToXml高级用法介绍 一.函数构造 什么是函数构造?其是指通过单个语句构建XML树的能力. 那么它有什么作用呢? 作用1.用单个表达式快速创建复杂的XML树 见实例代码CreateXml( ...

  9. 内核操作系统Linux内核变迁杂谈——感知市场的力量

    本篇文章个人在青岛游玩的时候突然想到的...今天就有想写几篇关于内核操作系统的博客,所以回家到以后就奋笔疾书的写出来发表了 Jack:什么是操作系统? 我:你买了一台笔记本,然后把整块硬盘彻底格式化, ...

  10. ASP.NET DropDownList FindByValue 未将对象引用设置到对象的实例 解决方法

    1.粗心把DataValueField中的字段名称写错了. 2.把DataBind()写在了FindByValue()后面了,以下代码是正确顺序: BLL.Student bllStu = new B ...