首先我们可以把所有位置都变为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的更多相关文章

  1. SQL Server 合并复制遇到identity range check报错的解决

        最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. [LeetCode] Range Addition 范围相加

    Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...

  4. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  5. [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 ...

  6. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  7. [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 ...

  8. [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

随机推荐

  1. centos8安装MySQL8——通过yum

    centos8上通过yum安装MySQL,过程简单,不易出错 1.检查系统是否已安装MySQL相关,如果有则全部清除干净 #列出MySQL相关的安装包 rpm -qa | grep mysql #依次 ...

  2. macbook air m1上传文件到github

    一,首先安装git,打开ssh文件里的id_rsa.pub,然后复制所有内容. 二,github上申请自己的账号,右上角settings里选择SSH and GPG keys,点击new ssh ke ...

  3. hmac和socketserver

    一,hmac 验证客户端的合法性 hmac,检测客户端是否合法,不依赖登录认证 server import os,socket,hmac sk=socket.socket() sk.bind(('12 ...

  4. JVM详解(三)——运行时数据区

    一.概述 1.介绍 类比一下:红框就好比内存的运行时数据区,在各自不同的位置放了不同的东西.而厨师就好比执行引擎. 内存是非常重要的系统资源,是硬盘和CPU的中间仓库及桥梁,承载着操作系统和应用程序的 ...

  5. 2020.10.16--vj个人赛补题

    D - Drinks Choosing Old timers of Summer Informatics School can remember previous camps in which eac ...

  6. 搭载Dubbo+Zookeeper踩了这么多坑,我终于决定写下这篇!

    大家好,我是melo,一名大二上软件工程在读生,经历了一年的摸滚,现在已经在工作室里边准备开发后台项目啦. 这篇文章我们不谈数据结构了,来谈谈入门分布式踩过的坑.感觉到了分布式这一层,由于技术更新迭代 ...

  7. UltraSoft - Beta - 发布声明

    1. Beta版本更新内容 新功能 (1)消息中心页面 课程爬取到新DDL.资源时会以通知的方式通知用户,本次同步更新了哪些内容一目了然.此外,当被作为参与成员添加DDL时也会通知.一些系统通知也会放 ...

  8. Java 16 新功能介绍

    点赞再看,动力无限.Hello world : ) 微信搜「程序猿阿朗 」. 本文 Github.com/niumoo/JavaNotes 和 程序猿阿朗博客 已经收录,有很多知识点和系列文章. Ja ...

  9. analysis_screencap

    #!/usr/bin/env pythonfrom PIL import Imageimg = Image.open("./screen.png")maps = [[] for i ...

  10. linux 内核源代码情景分析——linux 内存管理的基本框架

    386 CPU中的页式存管的基本思路是:通过页面目录和页面表分两个层次实现从线性地址到物理地址的映射.这种映射模式在大多数情况下可以节省页面表所占用的空间.因为大多数进程不会用到整个虚存空间,在虚存空 ...