[atAGC045C]Range Set
首先我们可以把所有位置都变为1,因此不妨假设$a\le b$
一个字符串$s$合法当且仅当:将其中每一段长度不小于$a$的0变成1后,存在一段1的长度都不小于$b$
证明:我们称$S_{a,b}$为通过$(a,b)$能产生的字符串所构成的集合,则有$S_{a,b}=S_{b,a}$
称原来的字符串为$s$,将每一段长度不小于$a$的0变成1后称为$s'$,则若$s'\in S_{a,b}$则可以得到$s\in S_{a,b}$,同时若有$s\in S_{b,a}$又可以得到$s'\in S_{b,a}$,即可得$s\in S_{a,b}$等价于$s'\in S_{a,b}$
接下来,就是证明$s'\in S_{a,b}$当且仅当存在一段1的长度都不小于$b$
必要性:考虑$s'$中不存在一段0的长度不小于$a$,又不存在一段1的长度不小于$b$,对最后一次操作分类讨论即可(初始$n\ge a,b$,也满足条件)
充分性:将长度不小于$b$的一段1变为0,则若可以得到这个串则一定可以得到$s'$,然后由于$b\ge a$,再把这段0和左右两边原来的0合并起来,长度不小于$a$,根据上面的结论,可以将这一段变为1
重复此操作,每一次操作必然减少一段0,因此最终即所有位置都为1,显然可以做到
统计不合法的字符串数量,假设已经确定$s'$,去统计对应为$s'$的$s$数量,考虑dp
预处理出用$g_{l}$表示将这段1中若干个位置改为0,且每一段0的长度都不小于$a$的方案数,再用用$f_{i,0/1}$表示前$i$个数,第$i$个数为0或1,简单转移即可

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 5005
4 #define mod 1000000007
5 int n,a,b,ans,g[N],f[N][N];
6 int main(){
7 scanf("%d%d%d",&n,&a,&b);
8 if (a>b)swap(a,b);
9 for(int i=0;i<a;i++)g[i]=1;
10 for(int i=a;i<=n;i++){
11 g[i]=(g[i-1]+1)%mod;
12 for(int j=a;j<i;j++)g[i]=(g[i]+g[i-j-1])%mod;
13 }
14 f[0][0]=f[0][1]=1;
15 for(int i=1;i<=n;i++)
16 for(int j=0;j<i;j++)
17 if (i-j<b){
18 int l=i-j-2;
19 if (!j)l++;
20 if (i==n)l++;
21 f[i][1]=(f[i][1]+1LL*f[j][0]*g[max(l,0)])%mod;
22 if (i-j<a)f[i][0]=(f[i][0]+f[j][1])%mod;
23 }
24 ans=1;
25 for(int i=0;i<n;i++)ans=ans*2%mod;
26 ans=(ans+mod-(f[n][0]+f[n][1])%mod)%mod;
27 printf("%d",ans);
28 }
[atAGC045C]Range Set的更多相关文章
- SQL Server 合并复制遇到identity range check报错的解决
最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- [LeetCode] Range Addition 范围相加
Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...
- [LeetCode] Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] Range Sum Query 2D - Immutable 二维区域和检索 - 不可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- CSS常见的5种垂直水平居中(面试够用)
方法一 (flex) <div id='box'> <div class='child'></div> </div> #box{ width:200px ...
- 2021年1月-第02阶段-前端基础-HTML+CSS进阶-VS Code 软件
软件安装 VSCode软件 能够安装 VS Code 能够熟练使用 VS Code 软件 能够安装 VS Code 最常用的插件 1. VS Code简介 1.1 VS Code 简介 Visual ...
- Mybatis 一级缓存 (20)
Mybatis中的一级缓存和二级缓存(本博文只是针对一级缓存说明) 概述 ORM框架一般都会有缓存机制,做为其中一员的Mybatis也存在缓存.功能是用以提升查询的效率和服务给数据库带来压力.同样的M ...
- python之字符串,列表,集合,字典方法
字典内置函数&方法 函数: 1.len(dict1):打印字典的键的个数 方法:dict1.( ) 2.clear():清空字典 3.copy():复制字典 4.fromkeys():使用指定 ...
- 更好的 java 重试框架 sisyphus 入门简介
What is Sisyphus sisyphus 综合了 spring-retry 和 gauva-retrying 的优势,使用起来也非常灵活. 为什么选择这个名字 我觉得重试做的事情和西西弗斯很 ...
- Unity——计时器功能实现
Unity计时器 Demo展示 介绍 游戏中有非常多的计时功能,比如:各种cd,以及需要延时调用的方法: 一般实现有一下几种方式: 1.手动计时 float persistTime = 10f flo ...
- 极速上手 VUE 3 —— teleport传送门组件
一.teleport 介绍 teleport 传送门组件,提供一种简洁的方式,可以指定它里面的内容的父元素.通俗易懂地讲,就是 teleport 中的内容允许我们控制在任意的DOM中,使用简单. 使用 ...
- abstract使用方式
springMVC中的 LocalContextHolder是一个 abstract类.里边方法都是static 的. 不能被继承.不能实例化.只能调用其定义的static 方法.这种 abstrac ...
- linux与windows下文件编码问题
注:转换操作均在Linux终端进行操作 DOS与Unix格式转换 安装工具:dos2unix.unix2dos # ubuntu apt-get install dos2unix apt-get in ...
- Noip模拟19(炸裂的开始) 2021.7.18
T1 u 差分与前缀的综合练习. 分析数据范围,只能是在修改的时候$O(1)$做到,那么只能是像打标记一样处理那个三角形 正解是建立两个二位前缀和,一个控制竖向,一个控制斜向 每次在三角的左上,右下, ...