Topic links
The main topic: there is a length of n 01 strings, you can each time the adjacent K-word match and, get a new character and get a certain score. Get the new word
Characters and fractions are determined by this K-character. You need to ask for the maximum score you can get.
Puzzle: Interval + pressure DP
See this for details.
My Harvest: 23333
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <
Algorithm> using namespace std;
#define N 305 #define LL long long int n,k;
int c[259],w[259];
ll F[n][n][259],inf;
Char Str[n];
inline void up (ll &x,ll y) {x=x>y?x:y;}
void work () {for (Int. l=2;l<=n;l++) for (int i=1;i<=n-l+1;i++) {int j=i+l-1,len=j-i;
while (len>=k) len-=k-1; for (int m=j;m>i;m-=k-1) for (int s=0; s< (1<<len); s++) if (f[i][m-1][s]!=inf) {if (F[m][j][0]!=inf) up (f[i][j][s<<1],f[i][m-
1][s]+f[m][j][0]);
if (F[m][j][1]!=inf) up (f[i][j][s<<1|1],f[i][m-1][s]+f[m][j][1]);
} if (len==k-1) {ll g[2];g[0]=g[1]=inf; for (int s=0; s< (1<<k); s++) if (f[i][j][s]!=inf) g[c[S]]=max (G[c[s]],f[i][j][s]+w[s]);
F[I][J][0]=G[0];F[I][J][1]=G[1];
}} cout<<*max_element (f[1][n],f[1][n]+ (1<<k)) <<endl;
} void Init () {scanf ("%d%d%s", &n,&k,str+1);
for (int i=0;i< (1<<k); i++) scanf ("%d%d", &c[i],&w[i]);
memset (F,128,sizeof (f)); inf=f[0][0][0];
for (int i=1;i<=n;i++) f[i][i][str[i]-' 0 ']=0;
} int main () {init ();
Work ();
return 0; }