Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 5000 + 100;
- int n, ans;
- char str[maxn];
- int dp[maxn][maxn];
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- ios::sync_with_stdio(false);
- cin >> (str + 1);
- n = strlen(str + 1);
- for (int len = 1; len <= n; ++len) {
- for (int l = 1; l + len - 1 <= n; ++l) {
- int r = l + len - 1;
- if (str[r] < str[l]) {
- dp[l][r] = 1;
- } else if (str[r] > str[l]) {
- dp[l][r] = -1;
- } else {
- dp[l][r] = dp[l + 1][r - 1];
- }
- if (dp[l][r] == 1) {
- ++ans;
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement