ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1167. Bicolored Horses

Can this problem get ac in a O(n^3) way without TLE??
Posted by Dont be shy 28 Aug 2003 16:36
Yes
Posted by Silviu Ganceanu 29 Aug 2003 02:37
  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!