文章目录
- 题目
- AC代码
题目
本博客给出本题截图:
AC代码
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <algorithm> using namespace std; const int N = 1010, mol = 10007; int f[N][N]; int main() { int T; cin >> T; int t = 1; while (T -- ) { string s; cin >> s; int n = s.size(); memset(f, 0, sizeof f); for (int i = 0; i < n; i ++ ) f[i][i] = 1; for (int len = 2; len <= n; len ++ ) for (int i = 0; i + len - 1 < n; i ++ ) { int j = i + len - 1; f[i][j] = (f[i + 1][j] + f[i][j - 1] - f[i + 1][j - 1] + mol) % mol; if (s[i] == s[j]) f[i][j] = (f[i][j] + f[i + 1][j - 1] + 1 + mol) % mol; } printf("Case %d: %d\n", t ++, f[0][n - 1] % mol); } return 0; }