题目大意:给你一个字符串,问至少添加几个字符串,才能使这个字符串变成回文串

解题思路:用dp[i][j]表示[i,j]内的字符需要添加几个字符才能变回文
考虑两种情况
1.str[i] == str[j],那么dp[i][j] = dp[i +1][j - 1]
2.str[i] != str[j],那么只能在左边添加一个,或者右边添加一个了
所以dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]) + 1

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;

char str[N];
int dp[N][N];
int cas = 1;

void solve() {
    scanf("%s", str);
    int n = strlen(str);
    memset(dp, 0, sizeof(dp));
    for (int len = 1; len < n; len++) {
        for (int i = 0; i + len < n; i++) {
            int j = i + len;
            if (str[i] == str[j]) dp[i][j] = dp[i + 1][j - 1];
            else dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]) + 1;
        }
    }
    printf("Case %d: %d\n", cas++, dp[0][n - 1]);
}


int main() {
    int test;
    scanf("%d", &test);
    while (test--) solve();
    return 0;
}