31std::string
lps(
const std::string& a) {
32 const auto b = std::string(a.rbegin(), a.rend());
33 const auto m = a.length();
34 using ind_type = std::string::size_type;
35 std::vector<std::vector<ind_type> > res(m + 1,
36 std::vector<ind_type>(m + 1));
41 for (ind_type i = 0; i <= m; i++) {
42 for (ind_type j = 0; j <= m; j++) {
43 if (i == 0 || j == 0) {
45 }
else if (a[i - 1] == b[j - 1]) {
46 res[i][j] = res[i - 1][j - 1] + 1;
48 res[i][j] = std::max(res[i - 1][j], res[i][j - 1]);
55 std::string ans(idx,
'\0');
56 ind_type i = m, j = m;
60 while (i > 0 && j > 0) {
63 if (a[i - 1] == b[j - 1]) {
64 ans[idx - 1] = a[i - 1];
71 else if (res[i - 1][j] > res[i][j - 1]) {