Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-04-16-03.32.23
- ***/
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- string a;
- ll dp[80][80];
- ll solve(ll i,ll j)
- {
- if(i>j) return 0;
- if(i==j) return 1;
- if(dp[i][j]!=-1) return dp[i][j];
- ll ans=0;
- if(a[i]==a[j])
- {
- ans=1+solve(i+1,j-1);
- }
- ans+=solve(i+1,j);
- ans+=solve(i,j-1);
- ans-=solve(i+1,j-1);
- return dp[i][j]=ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- cin>>a;
- memset(dp,-1,sizeof dp);
- cout<<solve(0,a.size()-1)<<nl;
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement