You are on page 1of 1

#include<bits\stdc+

+.h>
using namespace std;
string S;
int DP[1005][1005];
int solve(int a, int b){
int &res = DP[a][b];
if (res != 2e9) return res;
if (b <= a) return res = 0;
if (S[a] == S[b])
return res = solve(a + 1, b - 1);
else
return res = 1 + min(solve(a + 1, b), min(solve(a, b - 1),
solve(a + 1, b - 1)));
}
int main(){
int n;
scanf("%d", &n);
for
(int
i =
0; i
< n;
i++)
{
cin >> S;
for (int j = 0; j <= S.length(); j++)
for (int k = 0; k <= S.length(); k++)
DP[j][k] = 2e9;
printf("Case %d: %d\n", i + 1, solve(0, S.length() -
1));
}
return 0;
}

You might also like