CF370 D Memory and Scores
dp题 并运用了前缀和
我看题目提示中有fft 我想了下感觉复杂度不过关还是未解
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 4e5+5;
const int MOD = 1e9+7;
const int ze = 2e5;
ll dp[2][MAXN];
ll sum[MAXN];
int main(){
int a,b,k,t;
while(~scanf("%d %d %d %d",&a,&b,&k,&t)) {
memset(dp,0,sizeof(dp));
int fl= 1;
dp[1][ze] = 1; sum[0] = 0;
for(int i = 1; i <= t; ++i) {
for(int j = 1; j < MAXN; ++j) {
sum[j] = (dp[fl][j]+sum[j-1]) %MOD;
}
memset(dp[fl^1],0,sizeof(dp[fl^1]));
for(int j = 1; j < MAXN; ++j) {
int t1 = max(0,j-k-1); int t2 = min(MAXN-1, j+k);
dp[fl^1][j] = (dp[fl^1][j]+sum[t2]-sum[t1]+MOD) %MOD;
}
fl ^= 1;
}
for(int i = 1; i < MAXN; ++i) {
sum[i] = (dp[fl][i] + sum[i-1]) %MOD;
}
ll ans = 0;
for(int i = 1; i < MAXN; ++i) {
int tt = a-b+i;
if(tt >= MAXN) tt = MAXN;
if(tt < 1) tt = 1;
ans = (ans + dp[fl][i]*sum[tt-1]%MOD)%MOD;
}
printf("%lld\n",ans);
}
return 0;
}
CF370 D Memory and Scores的更多相关文章
- 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],也就是 ...
- 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 ...
- [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 - 712D]Memory and Scores (DP 或者 生成函数)
题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高. ( ...
- Codeforces 712 D. Memory and Scores (DP+滚动数组+前缀和优化)
题目链接:http://codeforces.com/contest/712/problem/D A初始有一个分数a,B初始有一个分数b,有t轮比赛,每次比赛都可以取[-k, k]之间的数,问你最后A ...
- CodeForces 712D Memory and Scores
$dp$,前缀和. 记$dp[i][j]$表示$i$轮结束之后,两人差值为$j$的方案数. 转移很容易想到,但是转移的复杂度是$O(2*k)$的,需要优化,观察一下可以发现可以用过前缀和来优化. 我把 ...
- CF712D Memory and Scores
题目分析 实际上两个人轮流取十分鸡肋,可以看作一个人取2t次. 考虑生成函数. 为了方便,我们对取的数向右偏移k位. 取2t次的生成函数为: \[ F(x)=(\sum_{i=0}^{2k}x_i)^ ...
随机推荐
- Springboot security cas整合方案-实践篇
承接前文Springboot security cas整合方案-原理篇,请在理解原理的情况下再查看实践篇 maven环境 <dependency> <groupId>org.s ...
- BZOJ 2986: Non-Squarefree Numbers [容斥原理 二分]
题意:求第$n \le 10^{10}$个不是无平方因子数 二分答案, 容斥一下,0个质数的平方因子-1个..... 枚举$\sqrt$的平方因子乘上莫比乌斯函数,最后求出无平方因子数的个数取补集 # ...
- BZOJ 3265: 志愿者招募加强版 [单纯形法]
传送门 一个人多段区间,一样.... 不过国家队论文上说这道题好像不能保证整数解.... #include <iostream> #include <cstdio> #incl ...
- BZOJ 3963: [WF2011]MachineWorks [CDQ分治 斜率优化DP]
传送门 当然了WF的题uva hdu上也有 你的公司获得了一个厂房N天的使用权和一笔启动资金,你打算在这N天里租借机器进行生产来获得收益.可以租借的机器有M台.每台机器有四个参数D,P,R,G.你可以 ...
- BZOJ 2631: tree [LCT splay区间]
2631: tree Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 3854 Solved: 1292[Submit][Status][Discus ...
- 读论文系列:Object Detection SPP-net
本文为您解读SPP-net: Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition Motivat ...
- 剑指offer试题(PHP篇一)
1.二维数组中的查找 题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. ...
- 在CentOS 6.x上配合Windows客户端搭建 git(gitosis)服务器
一.在 CentOS 上安装 git 和 gitosis: 逐条执行如下语句: sudo yum install git python-setuptools cd /opt sudo git clon ...
- 【JavaWeb】JDBC连接MySQL数据库
正文之前 在之前写的JavaWeb项目中使用了JDBC,在此来回顾一下,并做个demo看看,先来看看JDBC的概念 Java数据库连接,(Java Database Connectivity,简称JD ...
- 使用supervisor 进行进程管理时调整最大文件打开数
[supervisord]logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.loglogfile_maxbytes=50MB ; 日志文 ...