|
|
back to boardCan this problem get ac in a O(n^3) way without TLE?? Yes I got ACC with an program running in O(N^3) like this: If sol[i][j]=minimum unhappiness that it is obtained with the first i horses using j stables than sol[i][j]=min(sol[k][j-1]+ no[0]*no[1]) where k can take value between j-1 and i-1 and no[a] represent the number of horses coloured with 'a' from the interval [k+1, i]. You can use in this way O(N) memory and you can avoid getting MLE. Good luck! |
|
|