题意
[题目链接]这怎么发链接啊。。。。。
Sol
枚举一个断点,然后类似于LIS一样dp一波
这个边界条件有点迷啊。。fst了两遍。。。
#includeusing namespace std;const int MAXN = 1e5 + 10, INF = 1e9 + 7;inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f;}int N, f[101][101];class RepeatString{public: int solve(int pos, string s) { string a, b; a += '.'; b += '*'; memset(f, 0x3f, sizeof(f)); for(int i = 0; i < pos; i++) a += s[i]; for(int i = pos; i < N; i++) b += s[i]; int la = a.length() - 1, lb = b.length() - 1; f[0][0] = 0; for(int i = 0; i <= la; i++) f[i][0] = i; for(int i = 0; i <= lb; i++) f[0][i] = i; for(int i = 1; i <= la; i++) { for(int j = 1; j <= lb; j++) { f[i][j] = min(f[i - 1][j] + 1, f[i][j - 1] + 1); f[i][j] = min(f[i][j], f[i - 1][j - 1] + (a[i] != b[j])); } } return f[la][lb]; } int minimalModify(string s) { N = s.length(); int ans = N; for(int i = 0; i < N; i++) ans = min(ans, solve(i, s)); return ans; }};int main() { string s; cin >> s; cout << RepeatString().minimalModify(s);}/*pkafkbeabccfjejkdgkaatcedaocgmecaapakfvbfgefr*/