fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool isPall(long arr[],long s,long e)
  6. {
  7. while(s<e)
  8. {
  9. if(arr[s]!=arr[e])
  10. return false;
  11. s++;
  12. e--;
  13. }
  14. return true;
  15. }
  16.  
  17. long count(long arr[],long s,long e)
  18. {
  19. if(s>e)
  20. return 0;
  21. for(long i=e;i>=s;i--)
  22. {
  23. if(isPall(arr,s,i))
  24. {
  25. return 1+count(arr,i+1,e);
  26. }
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. long n;
  33. cin>>n;
  34.  
  35. long arr[n],i;
  36.  
  37. for(long i=0;i<n;i++)
  38. cin>>arr[i];
  39. cout<<count(arr,0,n-1);
  40. }
  41.  
Success #stdin #stdout 0s 4528KB
stdin
Standard input is empty
stdout
Standard output is empty