AT2292 Division into Two
lINK
不妨认为\(A>B\)。
首先判一下无解。
设\(f_i\)表示\(A\)集合最后选第\(i\)个数的方案数。
转移的话枚举一下从哪个\(j\)转移过来。
显然\(j\)需要满足以下条件:
\(j<i\)
\(S_j<S_i-A\)
\(\forall a,b\in(j,i)\wedge a<b,S_a<S_b-B\)
不难发现\(j\)的取值范围是一个区间,前缀和优化即可。
#include<cstdio>
#include<cctype>
#define ll long long
ll read(){ll x=0;int c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+c-48,c=getchar();return x;}
const int N=100007,P=1000000007;
int inc(int a,int b){return a+=b,a>=P? a-P:a;}
int dec(int a,int b){return a-=b,a<0? a+P:a;}
int mul(int a,int b){return 1ll*a*b%P;}
ll a[N],f[N],sum[N];
int main()
{
ll n=read(),A=read(),B=read(),i,l,r,ans=0;
if(A<B) A^=B^=A^=B;
for(i=1;i<=n;++i) a[i]=read();
for(i=1;i+2<=n;++i) if(a[i+2]-a[i]<B) return puts("0"),0;
f[0]=sum[0]=1,a[n+1]=B+a[n];
for(i=1,l=r=0;i<=n;++i)
{
while(r<i&&a[i]-a[r+1]>=A) ++r;
if(l<=r) f[i]=inc(f[i],dec(sum[r],l?sum[l-1]:0));
sum[i]=inc(sum[i-1],f[i]);
if(i>1&&a[i]-a[i-1]<B) l=i-1;
}
for(i=n;~i;--i)
{
ans=inc(ans,f[i]);
if(a[i+1]-a[i]<B) break;
}
printf("%d",ans);
}
AT2292 Division into Two的更多相关文章
- $AT2292\ Division\ into\ Two$ $dp$
正解:$dp$ 解题报告: 传送门$QwQ$ 不妨令$A\geq B$,于是先$sort$然后预处理判下如果有三个元素两两差都小于$B$的就直接$GG$了. 然后考虑对集合$X$进行$dp$,剩下的数 ...
- 「AT2292」Division into Two
传送门 Luogu 解题思路 考虑如何 \(\text{DP}\) 为了方便处理,我们设 \(A > B\) 设 \(dp[i]\) 表示处理完 \(1...i\) ,并且第 \(i\) 个数放 ...
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
- [LeetCode] Evaluate Division 求除法表达式的值
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- 关于分工的思考 (Thoughts on Division of Labor)
Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...
- POJ 3140 Contestants Division 树形DP
Contestants Division Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告
GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...
- Leetcode: Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
随机推荐
- JavaScript事件兼容性写法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- react-router-dom 实现左侧导航
1.介绍react-router-dom https://reacttraining.com/react-router/web/example/basic 这个官网有很多栗子可以练手 1.1 Hash ...
- Apicloud_(模板)登陆注册功能模板
项目已托管到Github上 传送门 不需要使用任何图片资源,需要用到SHA1.js库文件, Apicloud_(接口验证)用户注册头部信息X-APICloud-AppKey生成 传送门 项目全代码放到 ...
- Linux下运行scala语言的jar包
1.新建project 2.打包 3.linux下运行jar包 #First.jar为jar包名,Test为主类名 [root@FI-2 Desktop]# spark-submit First.ja ...
- Vue学习日记(二)——Vue核心思想
前言 Vue.js是一个提供MVVM数据双向绑定的库,其核心思想无非就是: 数据驱动 组件系统 数据驱动 Vue.js 的核心是一个响应的数据绑定系统,它让数据与DOM保持同步非常简单.在使用 jQu ...
- 小程序踩坑之获取不到e.target.dataset的值
在页面与js传值中我们经常用到data-id="1"的方式,然后通过e.target.dataset.id取id的值今天在获取值时怎么也取不到,后来发现e对象有currentTar ...
- redis-sentinel 主从复制高可用
Redis-Sentinel Redis-Sentinel是redis官方推荐的高可用性解决方案,当用redis作master-slave的高可用时,如果master本身宕机,redis本身或者客户端 ...
- Docker入门-数据挂载
Docker数据管理 在容器中管理数据主要有两种方式: 数据卷(Volumes) 挂载主机目录(Bind mounts) 数据卷 数据卷是一个可供一个或多个容器使用的特殊目录,它绕过UFS,可以提供很 ...
- Miniui 表单验证
自定义表单验证: input输入框的表单验证可通过vtype和onvalidation事件两种方式实现 可编辑列表(例如div)的表单验证只能通过vtye来实现表单验证 (1)vtype方式: jsp ...
- defineProperty和defineProperties介绍
v-model 实现的原理 angular 是 mvc 的实现原理,ng-model 是靠脏值检测实现的 脏值检测:for 循环一个个对比 vue 靠的是数据劫持 和 发布者,订阅者模式 数据劫持:O ...