题目解析:让你求出所有含单词的文章数量;
思路:考虑容斥原理,求出所有随机的方案,减去不可行的方案,得出最终结果;
考虑dp,求一个字母的前缀不可行方案,最终遍历每个结尾字母;
ac自动机来求出ne数组(fail指针)
总:ac自动机+dp+容斥原理;
code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110, M = 11000, mod = 10007;
typedef long long LL;
LL ch[M][26], ne[M], cnt[M], idx = 0, que[M], dp[M][M];
LL ans = 1;
char str[M];
int st[M];
inline void insert(char str[]) {
int p = 0, len = strlen(str);
for (int i = 0; i < len; i++) {
int u = str[i] - 'A';
if (!ch[p][u])
ch[p][u] = ++idx;
p = ch[p][u];
}
st[p] = 1;
}
inline void build() {
int q2 = 0;
for (int i = 0; i < 26; i++) {
if