CodeForces 712D Memory and Scores
$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的更多相关文章
- [CodeForces - 712D]Memory and Scores (DP 或者 生成函数)
题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高. ( ...
- 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 ...
- 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 ...
- Memory and Scores
Memory and Scores 题目链接:http://codeforces.com/contest/712/problem/D dp 因为每轮Memory和Lexa能取的都在[-k,k],也就是 ...
- [Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列)
[Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列) 题面 两个人玩游戏,共进行t轮,每人每轮从[-k,k]中选出一个数字,将其加到自己的总分中.已 ...
- 【26.87%】【codeforces 712D】Memory and Scores
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- Codeforces 712 D. Memory and Scores (DP+滚动数组+前缀和优化)
题目链接:http://codeforces.com/contest/712/problem/D A初始有一个分数a,B初始有一个分数b,有t轮比赛,每次比赛都可以取[-k, k]之间的数,问你最后A ...
- codeforces 712B. Memory and Trident
题目链接:http://codeforces.com/problemset/problem/712/B 题目大意: 给出一个字符串(由'U''D''L''R'),分别是向上.向下.向左.向右一个单位, ...
- codeforces 712A. Memory and Crow
题目链接:http://codeforces.com/problemset/problem/712/A 题目大意: 给你一个数字系列,求其满足条件的一个序列. 条件为: ai = bi - bi + ...
随机推荐
- 运动检测(前景检测)之(二)混合高斯模型GMM
运动检测(前景检测)之(二)混合高斯模型GMM zouxy09@qq.com http://blog.csdn.net/zouxy09 因为监控发展的需求,目前前景检测的研究还是很多的,也出现了很多新 ...
- CODEFORCES #272 DIV2[为填完]
#272是自己打的第一场cf,感觉这一套质量挺棒的,不像后两场略水 //先附上A,B,C的题解,因为离noip只剩下一点时间了,所以之后不一定还刷cf,暂且就先放上前三题好了 A题目大意忘了.懒得看, ...
- CentOS 6下安装nodejs 0.9.0(转)
确保安装了python,大部分安装失败都是由于python版本过低导致.安装之前,升级python版本,升级步骤 http://www.tomtalk.net/wiki/Python. [root@S ...
- 最长递增子序列(Longest Increase Subsequence)
问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱).例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8 ...
- MyEclipse8.5整合Git
下载Eclipse的git插件--EGit.官网地址: 点击打开链接 截止目前最新版本为3.5,历史版本如下: Release Version Release Date p2 repository U ...
- RTB撕开黑盒子 Part 4: Shady Bidding
在这篇文章中,我将告诉你"真实的出价"比你想的微妙,并且你可以使用基于ROI的pacing策略,不需要构建一个期望扣费的模型,你就可以得到完美的期望扣费模型. Same Same ...
- PhoneGap+Xcode6环境配置
安装PhoneGap,请先安装好NodeJS $ sudo npm install -g phonegap 创建项目 $ phonegap create my-app 编译项目 $ cd my-app ...
- Log in Spring
记录日志向来是企业级应用程序必须考虑的事情.早些年,一个项目一个日志功能或模块,然后有了log4j这样的产品.不知是log4j将记录日志做到了极致,或是技术含量不高,又或是经济利益不明显,它已成为了这 ...
- Jwalk发布——一个比较小的Js动画库
断断续续折腾了几个晚上终于于周日把Jwalk发布了,顺便用了下yahoo的前端框架-pure css ,很简洁,非常帅.推荐使用以下. 下面说下Jwalk是做什么的: 前端开发过程中经常会用到一些动画 ...
- Static 单例模式
Static 方法的问题 今天在看EhCache源码的时候,发现有一个这样的方法 这个是个典型的单例模式的工具类,但我所知道的单例模式的写法不是这样的,虽然<effect java>中 ...