[CC-BSTRLCP]Count Binary Strings

题目大意:

对于一个长度为\(n\)的\(\texttt0/\texttt1\)串\(S\),如果存在一个切分\(i\),使得\(S_{[1,i]}\)与\(S_{[i+1,n]}\)的LCP长度\(>k\),那么称\(i\)是\(S\)的精准切分。

如果\(S\)至少有\(m\)个精准切分,那么称\(S\)是一个切分串。

给定\(n,k,m\),求有多少长度为\(n\)的切分串。

  • \(1\le T\le 5\)
  • \(1\le n\le50\)
  • \(0\le m\le n-1\)
  • \(0\le k\le \min(10,n)\)

思路:

枚举前\(k\)位的状态\(s\),\(f[i][j][k]\)表示考虑到第\(i\)位,已经有\(j\)个精准切分,最后匹配的长度为\(k\)的方案数。

预处理每种后缀能匹配\(s\)的多长的前缀,转移时枚举最后加上\(0\)还是\(1\)即可。

时间复杂度\(\mathcal O(4^kk+2^kn^2k)\)。

源代码:

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
typedef long long int64;
const int N=51,K=11,M=1024,mod=1e9+7;
int f[2][N][K],g[M][K];
inline void upd(int &a,const int &b) {
(a+=b)%=mod;
}
int main() {
for(register int T=getint();T;T--) {
const int n=getint(),k=getint(),m=getint();
if(k==0) {
printf("%lld\n",(1ll<<n)%mod);
continue;
}
if(m+1==n||k*2>n) {
puts("0");
continue;
}
const int all=(1<<k)-1;
int ans=0;
for(register int s=0;s<=all/2;s++) {
int p[k+1];
for(register int i=0,t=s;i<=k;i++) {
p[k-i]=t;
t>>=1;
}
memset(f[0],0,sizeof f[0]);
for(register int t=0;t<=all;t++) {
for(register int i=1;i<=k;i++) {
int l;
for(l=i;l;l--) {
if(p[l]==(t&((1<<l)-1))) break;
}
g[t][i]=l;
}
f[0][t==s][g[t][k]]++;
}
for(register int i=k*2+1;i<=n;i++) {
const bool cur=i&1;
memset(f[cur],0,sizeof f[cur]);
for(register int j=0;j<=i;j++) {
for(register int i=0;i<=k;i++) {
for(register int b=0;b<2;b++) {
const int t=((p[i]<<1)|b)&all;
const int l=g[t][std::min(i+1,k)];
upd(f[cur][j+(l==k)][l],f[!cur][j][i]);
}
}
}
}
for(register int j=m+1;j<=n;j++) {
for(register int i=0;i<=k;i++) {
(ans+=f[n&1][j][i])%=mod;
}
}
}
printf("%d\n",(ans<<1)%mod);
}
return 0;
}

[CC-BSTRLCP]Count Binary Strings的更多相关文章

  1. 【Leetcode_easy】696. Count Binary Substrings

    problem 696. Count Binary Substrings 题意:具有相同个数的1和0的连续子串的数目: solution1:还不是特别理解... 遍历元数组,如果是第一个数字,那么对应 ...

  2. A. You Are Given Two Binary Strings…

    A. You Are Given Two Binary Strings… You are given two binary strings x and y, which are binary repr ...

  3. 696. Count Binary Substrings - LeetCode

    Question 696. Count Binary Substrings Example1 Input: "00110011" Output: 6 Explanation: Th ...

  4. [LeetCode] Count Binary Substrings 统计二进制子字符串

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  5. 696. Count Binary Substrings统计配对的01个数

    [抄题]: Give a string s, count the number of non-empty (contiguous) substrings that have the same numb ...

  6. LeetCode Count Binary Substrings

    原题链接在这里:https://leetcode.com/problems/count-binary-substrings/description/ 题目: Give a string s, coun ...

  7. [Swift]LeetCode696. 计数二进制子串 | Count Binary Substrings

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  8. LeetCode算法题-Count Binary Substrings(Java实现)

    这是悦乐书的第293次更新,第311篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第161题(顺位题号是696).给定一个字符串s,计算具有相同数字0和1的非空且连续子串 ...

  9. LeetCode 696 Count Binary Substrings 解题报告

    题目要求 Give a string s, count the number of non-empty (contiguous) substrings that have the same numbe ...

随机推荐

  1. 输出GPLT

    L1-023 输出GPLT (20 分)   给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符( ...

  2. 支持向量机-SMO算法简化版

    SMO:序列最小优化 SMO算法:将大优化问题分解为多个小优化问题来求解 SMO算法的目标是求出一系列的alpha和b,一旦求出这些alpha,就很容易计算出权重向量w,并得到分隔超平面 工作原理:每 ...

  3. CAS—认证原理

    CAS,Central Authentication Service—中央认证服务,是Yale 大学发起的一个企业级的.开源的项目,旨在为Web应用系统提供一种可靠的SSO解决方案.下面简单介绍SSO ...

  4. SRS流媒体服务器搭建+ffmpeg推流VLC取流观看

    一.编译SRS https://github.com/winlinvip/simple-rtmp-server 目前有1.0-release.2.0.3.0等版本 2.0官方文档地址:https:// ...

  5. Spark的Streaming + Flume进行数据采集(flume主动推送或者Spark Stream主动拉取)

    1.针对国外的开源技术,还是学会看国外的英文说明来的直接,迅速,这里简单贴一下如何看: 2.进入到flume的conf目录,创建一个flume-spark-push.sh的文件: [hadoop@sl ...

  6. 一脸懵逼学习Hadoop分布式集群HA模式部署(七台机器跑集群)

    1)集群规划:主机名        IP      安装的软件                     运行的进程master    192.168.199.130   jdk.hadoop      ...

  7. CentOS7安装wps

    https://blog.csdn.net/u010445843/article/details/77828552

  8. js 2017

    JS面向对象 <script> function num(val) { return val * 8 } function Index(name, age) { this.name = n ...

  9. Windows 7 编译64位boost库

    1. 官网下载boost 2. 解压boost到D:\Library\boost_1_64_0 3. 打开 VS2015 x64 本机工具命令提示符,输入 "d:" 回车,再输入 ...

  10. 【BZOJ2067】[Poi2004]SZN

    题解: 比上一题水多了 首先树上贪心,肯定要考虑儿子 然后我们会发现这个东西就是要先把儿子连起来 然后如果儿子个数为奇数我们可以把这一条和它连向父亲的并在一起 由于根没有父亲所以要单独考虑 答案就是s ...