-
Notifications
You must be signed in to change notification settings - Fork 0
/
1092_回文字符串.cc
69 lines (57 loc) · 1.15 KB
/
1092_回文字符串.cc
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
*
* Author : fcbruce <fcbruce8964@gmail.com>
*
* Time : Tue 26 Jan 2016 06:22:51 AM PST
*
*/
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;
typedef long long LL;
typedef int itn;
const int maxn = 1007;
const int maxm = 0;
int dp[maxn][maxn];
char buffer[maxn];
int dfs(int l, int r)
{
if (r - l < 1) return 0;
if (dp[l][r] < INF) return dp[l][r];
if (buffer[l] == buffer[r]) return dp[l][r] = dfs(l + 1, r - 1);
return dp[l][r] = std::min(dfs(l + 1, r), dfs(l, r - 1)) + 1;
}
int main()
{
#ifdef FCBRUCE
freopen("/home/fcbruce/code/t", "r", stdin);
#endif // FCBRUCE
scanf("%s", buffer);
int l = strlen(buffer);
memset(dp, 0x3f, sizeof dp);
printf("%d\n", dfs(0, l-1));
return 0;
}