【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

因为查询的字典里面。单词的最大长度为10
所以。
如果建立一棵字典树的话。
深度最多为10;
那么可以写一个DP;
设f[i]表示1..i这一段是否能被理解
f[0] = 1;
然后从从第i+1个位置开始扫描。
沿着树根往下走就好了。
(假设当前扫描的长度为len
遇到单词。
那么f[i+len]置为true.
在每个f[i]=1的位置都进行一次字典树的遍历就好。
1M=10^6
所以10^7的复杂度。
够了

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int L = 10;
const int N = 26;
const int M = 1e6; struct abc{
int cnt;
abc *nex[N+10];
}; int n,m,f[M+10];
abc *root;
char s[L+10],S[M+10]; abc *New_Node(){
abc *temp = new abc;
temp->cnt = 0;
for (int i = 0;i < 26;i++) temp->nex[i] = NULL;
return temp;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
root = New_Node();
scanf("%d%d",&n,&m);
rep1(i,1,n){
scanf("%s",s);
int len = strlen(s);
abc *temp = root;
for (int i = 0;i < len;i++){
if (temp->nex[s[i]-'a']==NULL){
temp->nex[s[i]-'a'] = New_Node();
}
temp = temp->nex[s[i]-'a'];
}
temp->cnt++;
} rep1(i,1,m){
scanf("%s",S+1);
int len = strlen(S+1);
f[0] = i;
for (int j = 0;j < len;j++)
if (f[j]==i){
abc *temp = root;
rep1(k,j+1,j+10){
if (k>len) break;
if (temp->nex[S[k]-'a']==NULL){
break;
}
temp = temp->nex[S[k]-'a'];
if (temp->cnt>0) f[k] = i;
}
}
int ans = 0;
rep1(j,1,len)
if (f[j]==i)
ans = j;
printf("%d\n",ans);
} return 0;
}

【BZOJ 1212】[HNOI2004]L语言的更多相关文章

  1. BZOJ 1212: [HNOI2004]L语言 [AC自动机 DP]

    1212: [HNOI2004]L语言 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1367  Solved: 598[Submit][Status ...

  2. BZOJ 1212: [HNOI2004]L语言( dp + trie )

    因为单词很短...用trie然后每次dp暴力查找...用哈希+dp应该也是可以的.... ------------------------------------------------------- ...

  3. BZOJ 1212 [HNOI2004]L语言 【AC自动机 + 背包】

    题目链接[http://www.lydsy.com/JudgeOnline/problem.php?id=1212] 题意:给你一些单词,然后给出一个没有标点的文本串S,都是小写字符.现在让你求用给出 ...

  4. BZOJ 1212 HNOI2004 L语言 AC自己主动机(Trie树)+动态规划

    标题效果:给定词的列表,并m串 每个字符串q个最长前缀,这个前缀可满足拆分成一些字符串 这些字符串中存在的词汇太 再也不怕错误的数据范围--有一个很明显Trie树能解决的问题竟然被我写的AC自己主动机 ...

  5. bzoj 1212: [HNOI2004]L语言 AC自动机+状压

    为什么这道题网上所有题解写的都是N*Len的trie树的暴力啊,4E的复杂度... 为什么暴力还跑这么快啊TAT.. 有一个O(Len)的做法就是先把AC自动机建出来,因为每个字典串的长度很小,所以我 ...

  6. bzoj 1212: [HNOI2004]L语言

    思路:字典树+dp, dp[ i ] 表示 前缀到 i 能不能被理解, 如果dp[ i ] 是能被理解的那么, 把i + 1, i + 2 ....  在字典树上走,走到一个单词就转移. ,这样可行的 ...

  7. BZOJ 1212: [HNOI2004]L语言 trie

    长度小于 10 是关键信息~ #include <cstdio> #include <cstring> #include <algorithm> #define N ...

  8. 1212: [HNOI2004]L语言

    1212: [HNOI2004]L语言 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 643  Solved: 252[Submit][Status] ...

  9. BZOJ P1212 [HNOI2004] L语言

    标点符号的出现晚于文字的出现,所以以前的语言都是没有标点的.现在你要处理的就是一段没有标点的文章. 一段文章T是由若干小写字母构成.一个单词W也是由若干小写字母构成.一个字典D是若干个单词的集合. 我 ...

  10. bzoj1212: [HNOI2004]L语言(字典树)

    1212: [HNOI2004]L语言 题目:传送门 题解: 看完题目之后就觉得可以暴力在字典树上之间询问,一开始还傻了以为用文章来建,肯定用单词啊: 那么我们可以用一个v数组表示当前字符串1~i的区 ...

随机推荐

  1. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep

    http://codeforces.com/contest/948/problem/A   A. Protect Sheep Bob is a farmer. He has a large pastu ...

  2. HDU 1576 A/B( 逆元水 )

    链接:传送门 思路: 现在给出 n = A % 9973,n = A - A/9973×9973,已知 B|A ,设 A = Bx,可以得到如下形式的式子:Bx + 9973×y = n ,因为gcd ...

  3. [学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 3 线性代数初步

    向量和矩阵 什么是矩阵/向量? Vectors and matrix are just collections of ordered numbers that represent something: ...

  4. HDU 2879

    利用x<n的信息,可以证得当n为素数时,he[n]=2;同时,若n 为素数,则有HE[N^K]=2;因为若等式成立则有n|x(x-1).抓住这个证即可. 至于符合积性函数,想了很久也没想出来,看 ...

  5. vue2 router中的 @ 符号表示src

    vue2 router中的 @ 符号表示src 学习了:https://segmentfault.com/q/1010000009549802 这个是webpack起的别名: 在build/webpa ...

  6. 1.RunLoop是什么?

    1.Run loops是线程相关的的基础框架的一部分. 一个run loop就是一个事件处理的循环.用来不停的调度工作以及处理输入事件.使用run loop的目的是让你的线程在有工作的时候忙于工作.而 ...

  7. 研读:AirBag Boosting Smartphone Resistance to Malware Infection

  8. jmeter脚本编写之五类常见请求编写

    1.普通post请求 2.普通json请求 3.带query參数的json请求 4.xml请求 5.上传请求 starting (Windows系统 点击 F12 调出开发人员工具,选择Network ...

  9. zzuoj--10424--无聊的课(简单几何)

    10424: 无聊的课 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 81  Solved: 16 [Submit][Status][Web Boar ...

  10. zzulioj--1712--神秘的数列(水题)

    1712: 神密的数列 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 122  Solved: 92 SubmitStatusWeb Board De ...