分析:
非常套路的状压DP套AC自动机水题。
就是找方案有点恶心。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<iostream>
#define SF scanf
#define PF printf
#define MAXN 110
#define MAXM 1030
#define MAXL 26
#define MAXS 26
using namespace std;
typedef long long ll;
struct node{
int tag;
char las;
node *fail;
node *ch[30];
}Tree[MAXN];
node* rt=Tree,*ncnt=Tree;
void insert(node *now,char *c,int id){
if(*c==0){
now->tag=id;
return ;
}
int d=*c-'a';
if(now->ch[d]==NULL){
ncnt++;
now->ch[d]=ncnt;
now->ch[d]->las=*c;
}
insert(now->ch[d],++c,id);
}
queue<node *> q;
void build(){
q.push(rt);
while(!q.empty()){
node *now=q.front();
q.pop();
for(int i=0