Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- int main() {
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- // Считываем строку
- std::string str;
- std::cin >> str;
- int n = (int) str.length();
- std::vector<std::vector<int>> count(1+n, std::vector<int>(1+n));
- // Заполняем исходную матрицу единичками при совпадающих символах, сразу "переворачивая" ее
- for (int i = 0; i < n; ++i)
- for (int j = i; j < n; ++j)
- count[n-i-1][j] = (str[i] == str[j]);
- // Ответ будет храниться в count[n][n] элементе - сумме всех элементов матрицы count[0..n-1][0..n-1], увеличенной на 1
- count[n][n] = 1;
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= n; ++j)
- if (count[i][j])
- for (int y = 0; y < i; ++y)
- for (int x = 0; x < j; ++x)
- count[i][j] += count[y][x];
- // Выводим ответ:
- std::cout << count[n][n]-1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement