fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. using namespace std;
  5.  
  6. bool checkpal(string s,int start,int end)
  7. {
  8. int i;
  9. for(i=start;i<=(start+end)/2;i++)
  10. {
  11. if(s[i]!=s[end+start-i])
  12. return false;
  13. }
  14. return true;
  15. }
  16.  
  17. int minp[10000][10000]={-1};
  18. int minpal(string s,int start,int end)
  19. {
  20. if(minp[start][end]!=-1)
  21. return minp[start][end];
  22. else if(end-start<=1)
  23. {
  24.  
  25. }
  26. else if(checkpal(s,start,end)==true)
  27. {
  28. minp[start][end]=0;
  29. return minp[start][end];
  30. }
  31. else
  32. {
  33. minp[start][end]=(minpal(s,start+1,end))<(minpal(s,start,end-1))?(minpal(s,start+1,end)):(minpal(s,start,end-1));
  34. minp[start][end]++;
  35. return minp[start][end];
  36. }
  37. }
  38. int main() {
  39. // your code goes here
  40. int n;
  41. scanf("%d",&n);
  42. string s;
  43. int i;
  44. for(i=0;i<n;i++)
  45. {
  46. scanf("%c",&s[i]);
  47. }
  48. s[i]='\0';
  49. int ans=minpal(s,0,n);
  50. printf("%d",ans);
  51. return 0;
  52. }
  53.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3
abc
compilation info
g++-4.9: internal compiler error: File size limit exceeded (program as)
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.
stdout
Standard output is empty