题解
动态规划会比枚举节省一点时间
C++ 代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1010;
bool f[N][N];
int main()
{
string s;
getline(cin, s);
int n = s.size();
int max_length = 0;
for (int i = 0; i < n; i ++ )
{
for (int j = 1; j <= i + 1; j ++ )
{
if (j == 1) f[i][j] = true;
else if (j == 2) {if (s[i] == s[i - 1]) f[i][j] = true;}
else {f[i][j] = f[i - 1][j - 2] & (s[i] == s[i - j + 1]);}
if (f[i][j] && j > max_length) max_length = j;
}
}
cout << max_length << endl;
return 0;
}
能请问一下f[i][j]含义吗
$大佬$