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 ...
随机推荐
- EF 操作数据库中的表
1.VS创建项目(实现数据库的增删改查.并在dataGridView中展示) 增.改通过Button,删通过快捷菜单ContextMenuStrip控件(DateGridView控件的ContextM ...
- [模板] 计算几何2: 自适应Simpson/凸包/半平面交/旋转卡壳/闵可夫斯基和
一些基本的定义在这里: [模板] 计算几何1(基础): 点/向量/线/圆/多边形/其他运算 自适应Simpson Simpson's Rule: \[ \int ^b_a f(x)dx\approx ...
- 安装MongoDB到CentOS 6
MongoDB是一个面向海量文档存数据动态存储的NoSQL型数据库.是一个除了用于关系型数据库如MySQL,PostgreSQL数据库表格的格式,和微软SQL以外的一种数据模型存储形式.他的功能包括了 ...
- STS热部署方法(springboot)
sts热部署,即是在项目中修改代码不用重新启动服务,提高效率. 方法如下: 1.在pom文件中引入 devtools 依赖: <dependency> <groupId> ...
- MyBaits理解?
(1)MyBaits是一个基于Java的持久层框架,支持普通或定制化SQL查询.存储过程以及高级映射,使用XML或注解来配置和映射信息. (2)应用程序使用SQLSessionFactory实例,一个 ...
- RocketMQ存储系统概要设计和源码解读
普遍消息存储技术的选型 分布式KV存储 NewSQL存储:TiDB 文件系统:RocketMQ,kafka,RabbitMQ RocketMQ:所有的message存储在一个log里,不区分topic ...
- js style.display = "" 和style.display="none" 区别
style.display = "":是清除display样式,display将使用默认值(块元素会变成block,内联元素会变成inline)style.display=&quo ...
- Uploading multiple files asynchronously by blueimp jquery-fileupload
Uploading multiple files asynchronously by blueimp jquery-fileupload Solved. Fiddle: http://jsfidd ...
- 使用DBLink方式同步远程数据库中含Blob、Clob字段表的问题解决
在数据库同步中我们经常会用到DBLink方式.DBLink可以将物理上存放于网络的多个数据库在逻辑上当成一个单一的大数据库.开发人员无需关心数据库的网络分布,就能很方便的实现从不同数据库之间读取数据. ...
- orcal 根据打分时间计算打分情况
create or replace function F_GET_TEST(in_ny in date,in_project_id in number ) return number is sRetu ...