BZOJ 1212: [HNOI2004]L语言 trie
2024-10-07 03:44:10
长度小于 10 是关键信息~
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1000000
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
struct Node {
int ch[27],end,len;
}t[N];
int n,m,tot,f[N];
char S[N];
void insert(int i) {
int rt=0,len=strlen(S+1),j;
for(j=len;j>=1;--j) {
if(!t[rt].ch[S[j]-'a']) t[rt].ch[S[j]-'a']=++tot;
t[t[rt].ch[S[j]-'a']].len=t[rt].len+1;
rt=t[rt].ch[S[j]-'a'];
}
t[rt].end=1;
}
int main() {
int i,j;
// setIO("input");
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
scanf("%s",S+1),insert(i);
f[0]=1;
for(int cas=1;cas<=m;++cas) {
scanf("%s",S+1);
int len=strlen(S+1);
for(i=1;i<=len;++i) {
int p=0;
f[i]=0;
for(j=i;j>=1;--j) {
p=t[p].ch[S[j]-'a'];
if(!p) break;
if(t[p].end) f[i]|=f[j-1];
}
}
int MX=0;
for(i=1;i<=len;++i) {
if(f[i]) {
MX=i;
}
}
printf("%d\n",MX);
}
return 0;
}
最新文章
- ASP.NET将文件写到另一服务器
- 【SpringMVC】SpringMVC系列9之Model数据返回到View
- Android设置背景图像重复【整理自网络】
- c# List集合排序
- 手机PC监听用户复制内容
- Intellij Error:Cannot build Artifact &#39;XXX:war exploded&#39; because it is included into a circular dependency
- PGM:部分有向模型之条件随机场与链图模型
- stark组件的分页,模糊查询,批量删除
- Hystrix系列-5-Hystrix的资源隔离策略
- C++类中一个构造函数调用另一个构造函数
- 在他机上还原DB2的备份
- Python logging 模块学习
- 手动增加pe节并修改oep
- 【oneday_onepage】——Microsoft addresses DevOps with InRelease technology
- Struts2+Hibernate+Spring(SSH)三大框架整合jar包
- HDU 6343 - Problem L. Graph Theory Homework - [(伪装成图论题的)简单数学题]
- Java数据结构和算法(一)概念
- Codeforces 1118 F2. Tree Cutting (Hard Version) 优先队列+树形dp
- Java学习笔记XML(3)
- Python【每日一问】17
热门文章
- 【Python】【demo实验3】【显示素数,显示两个数范围内的所有素数】
- Python中的 _init__和 _new__的区别
- java this的作用
- 2018.08.15【2018提高组】模拟A组 比赛总结
- EM 算法(三)-GMM
- 关于__name__==&#39;__main__&#39;的理解
- 最长上升子序列(Longest increasing subsequence)
- 第二篇 jQuery 选择器
- vue项目中使用mockjs+axios模拟后台数据返回
- mock.js 模拟数据