-
Notifications
You must be signed in to change notification settings - Fork 67
/
AIBOHP.cpp
46 lines (40 loc) · 984 Bytes
/
AIBOHP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <cassert>
#include <iomanip>
#include <ctime>
using namespace std;
const int me = 7025;
int t, n;
char a[me], b[me];
int dp[me][me];
int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
scanf("%d", &t);
while(t --){
scanf(" %s", a);
n = (int)strlen(a);
for(int i = 0; i < n; i ++)
b[i] = a[n - 1 - i];
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++){
if(a[i] == b[j])
dp[i][j] = (i > 0 && j > 0)? dp[i - 1][j - 1] + 1 : 1;
else dp[i][j] = max((i > 0)? dp[i - 1][j] : 0, (j > 0)? dp[i][j - 1] : 0);
}
printf("%d\n", n - dp[n - 1][n - 1]);
}
return 0;
}