Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- string s;
- int get(int l, int r) {
- if (l > r) return 0;
- if (l == r) return 1;
- int ans = 0;
- int a1 = get(l, r - 1);
- int a2 = get(l + 1, r);
- int a3 = get(l + 1, r - 1);
- ans += a1 + a2 - a3;
- if (s[l] == s[r]) {
- ans += get(l + 1, r - 1) + 1;
- }
- return ans;
- }
- int main(){
- cin >> s;
- n = s.size();
- s = ' ' + s;
- cout << get(1, n) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement