fork download
  1.  
  2.  
  3.  
  4. ////////////////////// PLEASE PASTE THIS CODE TO LEETCODE PALINDROMIC PARTITION PAGE
  5.  
  6. #define ll long long int
  7. class Solution {
  8. ll dp[1501][1501];
  9. ll pal[1501][1501];
  10.  
  11. ll palindrome_partition(string &s,ll i, ll j)
  12. {
  13. if(dp[i][j]!=-1) return dp[i][j]; // step 3
  14.  
  15. if(i>j)
  16. return dp[i][j]=0; // it means we no more cuts required.
  17.  
  18.  
  19.  
  20. if(pal[i][j]) return dp[i][j]=0;
  21.  
  22. ll mina=INT_MAX;
  23. for(ll k=i;k<=j-1;k++)
  24. {
  25. ll left=dp[i][k],right=dp[k+1][j]; ll tempans=0;
  26. if(left==-1)
  27. left=palindrome_partition(s,i,k);
  28. if(right==-1)
  29. right=palindrome_partition(s,k+1,j);
  30.  
  31. tempans=left+right+1;
  32. mina=min(mina,tempans);
  33. }
  34.  
  35. return (dp[i][j]=mina);
  36. }
  37. public:
  38. int minCut(string s) {
  39. if(s.length()==0) return 0;
  40. memset(dp,-1,sizeof(dp));
  41. memset(pal,0,sizeof(pal));
  42. ll n=s.length();
  43. for(int i=0;i<n;i++)
  44. pal[i][i]=1;
  45.  
  46. // explicitly for 2 length
  47. for(int i=0;i<n-1;i++)
  48. {
  49. if(s[i]==s[i+1])
  50. pal[i][i+1]=1;
  51. }
  52.  
  53. for(int i=2;i<n;i++)
  54. {
  55. for(int j=0;j+i<n;j++)
  56. {
  57. if(s[j]==s[j+i] and pal[j+1][j+i-1]==1)
  58. pal[j][j+i]=1;
  59. }
  60. }
  61.  
  62. return palindrome_partition(s,0,n-1);
  63. }
  64. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:11:25: error: ‘string’ has not been declared
 ll palindrome_partition(string &s,ll i, ll j)
                         ^~~~~~
prog.cpp:33:16: error: ‘string’ has not been declared
     int minCut(string s) {
                ^~~~~~
prog.cpp: In member function ‘long long int Solution::palindrome_partition(int&, long long int, long long int)’:
prog.cpp:21:10: error: ‘INT_MAX’ was not declared in this scope
  ll mina=INT_MAX;
          ^~~~~~~
prog.cpp:21:10: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 
prog.cpp:21:10:
  ll mina=INT_MAX;
          ^~~~~~~
prog.cpp:27:8: error: ‘min’ was not declared in this scope
   mina=min(mina,tempans);
        ^~~
prog.cpp:27:8: note: suggested alternative: ‘mina’
   mina=min(mina,tempans);
        ^~~
        mina
prog.cpp: In member function ‘int Solution::minCut(int)’:
prog.cpp:34:14: error: request for member ‘length’ in ‘s’, which is of non-class type ‘int’
         if(s.length()==0) return 0;
              ^~~~~~
prog.cpp:35:9: error: ‘memset’ was not declared in this scope
         memset(dp,-1,sizeof(dp));
         ^~~~~~
prog.cpp:35:9: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
prog.cpp:1:1:
+#include <cstring>
 
prog.cpp:35:9:
         memset(dp,-1,sizeof(dp));
         ^~~~~~
prog.cpp:37:16: error: request for member ‘length’ in ‘s’, which is of non-class type ‘int’
         ll n=s.length();
                ^~~~~~
prog.cpp:44:10: error: invalid types ‘int[int]’ for array subscript
    if(s[i]==s[i+1])
          ^
prog.cpp:44:18: error: invalid types ‘int[int]’ for array subscript
    if(s[i]==s[i+1])
                  ^
prog.cpp:52:11: error: invalid types ‘int[int]’ for array subscript
     if(s[j]==s[j+i] and pal[j+1][j+i-1]==1)
           ^
prog.cpp:52:19: error: invalid types ‘int[int]’ for array subscript
     if(s[j]==s[j+i] and pal[j+1][j+i-1]==1)
                   ^
stdout
Standard output is empty