题目链接:868D - Huge Strings

题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值。定义一个新串的价值\(k\)为:最大的\(k\),使得这个新串包含所有长度为\(k\)的01串(这样的字符串有\(2^k\)个)

题解:首先来证明对于任何的串,这个\(k\)的值不会超过9

   若\(k=10\),由所有字符串的长度总和不超过100,因此在初始的\(n\)个串里,互不相同的长度为\(k\)的子串不超过100个。又由于每次连接最多能产生9个新的长度为\(k\)的子串(即横跨两个字符串之间的子串),因此互不相同的子串个数最多为\(9 \cdot100+100<2^k\),故\(k<10\)

   接下来就只需要记录每个字符串的前缀,后缀以及长度为\(k\)的子串有哪些就好了。

#include<bits/stdc++.h>
using namespace std;
#define N 101
int n,m,a,b;
struct rua
{
string st,ed;
set<int>has[];
bool check(int k)
{
for(int i=;i<(<<k);i++)
if(!has[k].count(i))return false;
return true;
}
int ans()
{
for(int k=;k>;k--)
if(check(k))return k;
return ;
}
rua connect(rua nxt)
{
rua res=nxt;
res.st=st;
if(st.size()<)
res.st=st+nxt.st.substr(,min(nxt.st.size(),-st.size()));
int cpy_len=min(ed.size(),-nxt.ed.size());
if(nxt.ed.size()<)
res.ed=ed.substr(ed.size()-cpy_len,cpy_len)+nxt.ed;
for(int k=;k<=;k++)
for(auto i:has[k])res.has[k].insert(i);
string tmp=ed+nxt.st;
int len=tmp.size();
for(int i=;i<len;i++)
{
int value=;
for(int d=;d< && i+d<len;d++)
value=value*+tmp[i+d]-'',
res.has[d+].insert(value);
}
return res;
}
}f[*N];
string s;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
cin>>s;
int len=s.size();
for(int j=;j<len;j++)
{
int value=;
for(int d=;d< && j+d<len;d++)
value=value*+s[j+d]-'',
f[i].has[d+].insert(value);
}
int cpy_len=min(,len);
f[i].st=s.substr(,cpy_len);
f[i].ed=s.substr(len-cpy_len,cpy_len);
}
scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
f[n+i]=f[a].connect(f[b]);
printf("%d\n",f[n+i].ans());
}
}

[Codeforces Round #438][Codeforces 868D. Huge Strings]的更多相关文章

  1. [Codeforces Round #438][Codeforces 868C. Qualification Rounds]

    题目链接:868C - Qualification Rounds 题目大意:有\(n\)个题目,\(k\)个人,每个人可能做过这\(n\)个题里的若干道,出题方要在这\(n\)个题目里选若干个出来作为 ...

  2. Codeforces Round #438 (Div.1+Div.2) 总结

    本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...

  3. 【Codeforces Round 438 A B C D 四个题】

    题目所在比赛的地址在这里呀 A. Bark to Unlock ·述大意:       输入一个目标串.然后输入n(1<=n<=100)个串,询问是否可以通过这些串收尾相接或者它本身拼出目 ...

  4. D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

    http://codeforces.com/contest/868/problem/D 优化:两个串合并 原有状态+ 第一个串的尾部&第二个串的头部的状态 串变为第一个串的头部&第二个 ...

  5. Codeforces Round #438 D. Huge Strings

    Description You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations a ...

  6. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  7. Codeforces Round #188 (Div. 2) B. Strings of Power 水题

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  8. Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

    A. Bark to Unlock 题目链接:http://codeforces.com/contest/868/problem/A 题目意思:密码是两个字符组成的,现在你有n个由两个字符组成的字符串 ...

  9. Codeforces Round #438 B. Race Against Time

    Description Have you ever tried to explain to the coordinator, why it is eight hours to the contest ...

随机推荐

  1. 第七节:WebApi与Unity整合进行依赖注入和AOP的实现

    一. IOC和DI 1. 通过Nuget引入Unity程序集. PS:[版本:5.8.6] 2. 新建DIFactory类,用来读取Unity的配置文件并创建Unity容器,需要注意的是DIFacto ...

  2. word中中文保持正体,英文用斜体的方法.

    有时候,大段的文字中夹杂着英文字母,英文需要斜体,如果一个接一个选中再斜体,费时费力,那么怎样快速实现文斜体中文不斜体呢? 工具/原料 word软件 方法/步骤 选中要修改的段落,替换-查找内容-特殊 ...

  3. windows下 cmd 界面的替代者 cmder 推荐!

    介绍 http://cmder.net/ Portable console emulator for Windows Cmder is a software package created out o ...

  4. 【JS】CharToAsciiToBinaryToAsciiToChar

    <!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js&qu ...

  5. Django REST Framework API Guide 08

    1.Filtering 2.Pagination FIltering GenericAPIView的子类筛选queryset的简单方法是重写.get_quueryset()方法. 1.根据当前用户进行 ...

  6. Idea 创建控制台程序

    1:前提配置好 jdk环境. 最后一步:填写项目名称和保存的路径 即可.

  7. VS中展开和折叠代码,还有其他快捷操作

    [转]VS中展开和折叠代码   VS2005代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代码和折叠代码所用到的快捷键,很常用: Ctrl + M + O: 折叠所有方法 Ctrl + M + ...

  8. Python-form表单标签

    语义:标记表单 #1.什么是表单? 表单就是专门用来接收用户输入或采集用户信息的 #2.表单的格式 <form> <表单元素> </form> 链接:https:/ ...

  9. unity读取txt,并且生成vector3的数组

    读取txt的脚本: public void ReadFileTX(){ var str = File.ReadAllText(Application.streamingAssetsPath + &qu ...

  10. 库数据有则修改,无则新增sql

    方法一:insert中on duplicate key update的使用 例如: <insert id="bindPlaceInfo"> insert into gr ...