-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloj1033.cpp
More file actions
46 lines (35 loc) · 822 Bytes
/
loj1033.cpp
File metadata and controls
46 lines (35 loc) · 822 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
39
40
41
42
43
44
45
46
using namespace std;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
int dp[1010][1010];
char str[1010];
bool visited[1010][1010];
int solve(int l1,int l2)
{
if(l1>l2)
return 0;
if(visited[l1][l2])
return dp[l1][l2];
visited[l1][l2]=true;
if(str[l1]==str[l2])
return dp[l1][l2]=solve(l1+1,l2-1);
else
{
return dp[l1][l2]=1+min(solve(l1+1,l2),solve(l1,l2-1));
}
}
int main()
{
int t,Case=1;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
int l=strlen(str);
memset(visited,false,sizeof(visited));
printf("Case %d: %d\n",Case++,solve(0,l-1));
}
return 0;
}