-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10739.cpp
More file actions
38 lines (32 loc) · 813 Bytes
/
uva10739.cpp
File metadata and controls
38 lines (32 loc) · 813 Bytes
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
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
char word[1100];
int dp[1100][1100];
int find_ans() {
memset(dp, 0, sizeof(dp));
int len = strlen(word);
for(int i = len - 1; i >= 0; --i) {
for(int j = i + 1; j < len; ++j) {
if(word[j] == word[i])
dp[i][j] = dp[i + 1][j - 1];
else {
dp[i][j] = std::min(dp[i + 1][j], dp[i][j - 1]);
dp[i][j] = std::min(dp[i][j], dp[i + 1][j - 1]);
dp[i][j] += 1;
}
}
}
return dp[0][len - 1];
}
int main() {
// freopen("input.txt", "r", stdin);
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i ){
scanf("%s", word);
printf("Case %d: %d\n", i, find_ans());
}
return 0;
}