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 ...
随机推荐
- head first 设计模式笔记9-迭代器模式
迭代器模式:提供一种方法顺序访问一个集合对象中的各个元素,而又不暴露其内部的表示. 迭代器接口 /** * @author oy * @date 2019年9月22日 上午9:03:08 * @ver ...
- c# 使用Split分割 换行符
c# 使用Split分割 换行符,方法如下(其余方法有空再添加): string str = "aa" + "\r\n" + "bb"; s ...
- luogu 2993 [FJOI2014]最短路径树问题 Dijkstra+点分治
挺简单的,但是给人一种把两个问题强行弄到一起的感觉. 十分不好写. Code: #include <queue> #include <cstdio> #include < ...
- [CSP-S模拟测试]:花(DP)
题目传送门(内部题111) 输入格式 一个整数$T$,表示测试数据组数. 每组测试数据占一行,两个整数,分别表示$L$和$S$. 输出格式 对每组数据,输出一个整数表示答案. 样例 样例输入1: 13 ...
- Java使用阿里云OSS对象存储上传图片
原 Java使用阿里云OSS对象存储上传图片 2017年03月27日 10:47:28 陌上桑花开花 阅读数 26804更多 分类专栏: 工作案例总结 版权声明:本文为博主原创文章,遵循CC 4.0 ...
- conda查看某个安装包的依赖项
查看某个安装包XXX的依赖项的conda指令为: conda search XXX -info 比如XXX为pytorch0.3.1,就会有如下输出: pytorch 0.3.1 py36hfbe70 ...
- python3笔记三:运算符与表达式
一:学习内容 算术运算符:+(加).-(减).*(乘)./(除).%(取模).**(求幂).//(取整) 赋值运算符:= 复合运算符:+=.-=.*=./=.%=.**=.//= 位运算符:& ...
- 使用Desktop App Converter打包桌面应用程序
打包具有安装程序 (.msi) 的应用程序 DesktopAppConverter.exe -Installer C:\Installer\MyAppSetup.msi -Destination C: ...
- 阿里镜像源配置yum
通过more /etc/*release* 查看系统版本 (需要下载对应的系统版本) mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cen ...
- Hidden的应用
在写jsp中如果一个 请求的参数(例如:paramTypeCode)不能在另一个请求中使用,我们为了能让他在请求中使用可以利用隐藏域来表示,下面介绍他的用法: 1 <input type= ...