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 ...
随机推荐
- Python天天学_03_基础三
Python_day_03 金角大王: http://www.cnblogs.com/alex3714/articles/5740985.html ------Python是一个优雅的大姐姐 学习方式 ...
- HDU 6155 Subsequence Count (DP、线性代数、线段树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6155 题解 DP+线代好题.(考场上过多时间刚前两题,没怎么想这题--) 首先列出一个DP式: 设\( ...
- [LOJ3109][TJOI2019]甲苯先生的线段树:DP
分析 首先,请允许我 orz HN队长zsy.链接 我们发现树上的链有两种类,一类是直上直下的,一类不是直上直下的(废话).并且,如果我们确定了左侧和右侧的链的长度和整条链上所有节点的编号之和,那么这 ...
- Apicloud_(接口验证)用户注册头部信息X-APICloud-AppKey生成
接口验证KEY生成规则说明 官方文档: 传送门 "X-APICloud-AppKey"生成规则是基于SHA1()算法生成的 AppKey= SHA1(你的应用ID + 'UZ' + ...
- 利用freemarker生成word,word另存为xml文件的标签解析
http://wenku.baidu.com/link?url=YxTZWVP3ssO-e_Br3LIZVq2xOQnqaSz8gLPiRUDN8NIR_wX2-Z25OqwbVn5kXqGiOFYU ...
- vue2.0中watch总结:普通监听和深度监听
watch:{} 是一个对象,一定要当成对象来用,可监听数据,是vue中数据发生变化进行处理的函数, 它有三个选项 第一个handler:其值是一个回调函数.即监听到变化时应该执行的函数.第二个是de ...
- jpa repostiory
JpaRepository的查询 image.png image.png Spring Data JPA框架在进行方法名解析时,会先把方法名多余的前缀截取掉,比如 find.findBy.re ...
- Docker入门-常用命令
Docker镜像操作 Docker运行容器前需要本地存在对应的镜像,如果本地不存在该镜像,Docker会从镜像仓库下载该镜像. 获取镜像 从Docker镜像仓库获取镜像的命令是docker pull. ...
- VS部分安全函数用法
在 VS(Visual Studio)下编译C语言程序,有时候VS会报错,提示用到的一些函数可能不安全,并且建议替换为带有_s后缀的安全函数. 安全函数是什么 scanf().gets().fgets ...
- 使用ffmpeg切片出hls
测试的时候经常要用到ffmpeg切hls的流 ffmpeg -re -i g:/media/baifa.mp4 -codec copy -f hls -hls_list_size -hls_wrap ...