--- title: "加密信息" created: 2025-11-28 tags: - 算法 --- # 加密信息 ## 题目 [加密信息](https://www.acwing.com/problem/content/description/4194/) ![[image-6e35fc70.png]] ## 思路分析 M串和N串长度并没有严格大小之分,所以存在两种情况,一种是N串是M串的子串,另一种是M串是N串的子串 对于这两种子串,我们都需要经过Trie树某一个点之后的字符串数量,以及以这个点为结尾的字符串数量 注意 它这的读入是带空格的 110这个字符串 成1 1 0读入 所以用char读入 拼成string ## 代码实现 ```cpp #include using namespace std; const int M=500010; int son[M][2],idx; int ed[M],st[M]; void insert(string s) { int p=0; int len=s.length(); for(int i=0;i>k; for(int j=1;j<=k;j++){ char c; cin>>c; s+=c; } insert(s); } for(int i=1;i<=m;i++){ int k; string s; cin>>k; for(int j=1;j<=k;j++){ char c; cin>>c; s+=c; } printf("%d\n",query(s)); } return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[前缀统计|前缀统计]] 🏠 [[00-刷题理模型]] ➡️ [[字典树|字典树]]