Advertisement
a53

CountPal

a53
Dec 19th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #define M 777013
  4. using namespace std;
  5. char s[5001];
  6. int dp[5001];
  7.  
  8. bool pal(int a,int b)
  9. {
  10. --a,--b;
  11. while(a<b&&s[a]==s[b])
  12. ++a,--b;
  13. if(a>=b)
  14. return true;
  15. return false;
  16. }
  17.  
  18. int main ()
  19. {
  20. ios_base::sync_with_stdio(false);
  21. cin.getline(s,5001);
  22. int n=strlen(s);
  23. dp[0]=1;
  24. for(int i=1;i<=n;++i)
  25. {
  26. dp[i]+=dp[i-1],dp[i]%=M;
  27. for(int j=1;j<i;++j)
  28. if(pal(j,i))
  29. dp[i]+=dp[j-1],dp[i]%=M;
  30. }
  31. cout<<dp[n];
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement