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)^ ...
随机推荐
- elasticsearch的percolator操作
es的普通查询是通过某些条件来查询满足的文档,percolator则不同,先是注册一些条件,然后查询一条文档是否满足其中的某些条件. es的percolator特性在数据分类.数据路由.事件监控和预警 ...
- java文件监控[转]
原文链接:http://blog.csdn.net/dancen/article/details/7786987#comments 问题:存在两个文件目录,且称之为源目录和目标目录,需要不定期将源目录 ...
- BZOJ 3168: [Heoi2013]钙铁锌硒维生素 [线性基 Hungary 矩阵求逆]
3168: [Heoi2013]钙铁锌硒维生素 题意:给一个线性无关组A,再给一个B,要为A中每个向量在B中选一个可以代替的向量,替换后仍然线性无关.判断可行和求字典序最小的解 PoPoQQQ orz ...
- 像我这样优雅地进行Spring整合MongoDB
本文重点是要将mongodb与spring整合到项目中去,在实践中发现问题,追踪问题,然后解决问题. 一.准备 Maven.Spring(spring-data-mongodb) spring Dat ...
- git使用步骤_2017
(部署项目) zbot deploy developer git对文件chmod 777后导致status发生变化,使用: git config core.fileMode false [当 ...
- Ubuntu 配置FTP服务器
第三方的文件传输软件用着很不爽,想着自己搭建一个FTP来干活. 首先检查是否已经安装了FTP,输入命令: vsftpd -v 可以查看版本,如果没有安装,无法执行. 安装FTP p.p1 { mar ...
- Git环境配置+VSCode中文乱码问题
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html 1.VSCode中文乱码问题 (files.autoguessEncoding= ...
- Spring_Spring与DAO_Spring的Jdbc模板
一.导入Jar包 二.定义实体类与DB表 public class Student { private Integer id; private String name; private int age ...
- Egret学习笔记 (Egret打飞机-6.实现敌机飞起来)
有了子弹,总得有敌人来打吧,不然游戏有啥意思呢?今天我们来实现敌机从屏幕上边往下飞 参考微信打飞机游戏里面,敌机分为3种 1是特小飞机,2是小飞机,还有一种就是大飞机 面向对象编程提倡抽象,实现代码复 ...
- HZAU 1199: Little Red Riding Hood 01背包
题目链接:1199: Little Red Riding Hood 思路:dp(i)表示前i朵花能取得的最大价值,每一朵花有两种选择,摘与不摘,摘了第i朵花后第i-k到i+k的花全部枯萎,那么摘的话d ...