[线头DP]LOJ 2687 vim
分析
线头瞎搞
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=7e4+10; const int Alpha=11; const int Inf=0x7f7f7f7f; int len,fakelen,cnt,le[N],f[N][Alpha],g[N][Alpha][Alpha],s[N]; char c[N]; int main() { scanf("%d",&len); scanf("%s",c+1); for (int i=1;i<=len;i++) { if (c[i]!='e') le[++fakelen]=c[i-1]=='e',s[fakelen]=c[i]-'a'; cnt+=(c[i]=='e'); } memset(f,0x7f,sizeof f);memset(g,0x7f,sizeof g); f[0][s[1]]=0; for (int i=1;i<=fakelen;i++) for (int j=0;j<Alpha;j++) { f[i][j]=min(j!=s[i]&&!le[i]?f[i-1][j]:Inf, min(f[i-1][s[i]]+2,min(j!=s[i]?g[i-1][s[i]][j]:Inf,g[i-1][s[i]][s[i]]+2))); for (int k=0;k<Alpha;k++) g[i][j][k]=min(j!=s[i]?f[i-1][j]+3:Inf,min(f[i-1][s[i]]+5,min(j!=s[i]&&k!=s[i]?g[i-1][j][k]+1:Inf, min(j!=s[i]?g[i-1][j][s[i]]+3:Inf,min(k!=s[i]?g[i-1][s[i]][k]+3:Inf,g[i-1][s[i]][s[i]]+5))))); } printf("%d",f[fakelen][Alpha-1]-2+2*cnt); }
在日渐沉没的世界里,我发现了你。