构造n长串,若含有模板串x可获得a[x]的价值,同价值取字典序最小,输出路径
dp[i][j]表示长度i转移态j的最大价值,对应一个path[i][j]记录路径
#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define FOR(a) for(int i=1;i<=a;i++) const int inf=0x3f3f3f3f; const int maxn=1e6+7; const long long mod=1e9+7; const int sigma=26; ll ans; int a[110]; int dp[55][1111]; //串长i匹配到j位置最大价值 string path[55][1111]; //路径 struct automata{ int ch[maxn][sigma]; int val[maxn]; int f[maxn]; int sz; int newnode(){ memset(ch[sz],0,sizeof(ch[sz])); f[sz]=val[sz]=0; return sz++; } void init(){ memset(val,0,sizeof(val)); sz=0; newnode(); } void insert(char *s,int v){ int u=0; int len=strlen(s); for(int i=0;i dp[i+1][u]){ dp[i+1][u]=dp[i][j]+a[val[u]]; path[i+1][u]=path[i][j]+(char)(k+'a'); continue; } if(dp[i][j]+a[val[u]]==dp[i+1][u]){ string str=path[i][j]; str.pb(k+'a'); if(strpath[row][j]||str=="")) str=path[row][j]; } cout<q; q.push(0); while(!q.empty()){ int u=q.front();q.pop(); if(val[f[u]]){ //val[u]=(val[u]+val[f[u]]; a[val[u]]+=a[val[f[u]]]; } for(int i=0;i