The Uncertainty of Politics: Difference between revisions

From programming_contest
Jump to navigation Jump to search
imported>Kmk21
Created page with "# Order meetings 1->N by start time # solution is expected value of 1, or E(1) # E(n) calculated as max of ## E(n+1) meaning we didn't attend this meeting ## 1 + sum (E(n+x) *..."
 
imported>Kmk21
No edit summary
Line 16: Line 16:
[[Category:Dynamic Programming]]
[[Category:Dynamic Programming]]
[[Category:Probability]]
[[Category:Probability]]
[[Category:Expected value]]
[[Category:Expected Value]]

Revision as of 04:16, 3 December 2017

  1. Order meetings 1->N by start time
  2. solution is expected value of 1, or E(1)
  3. E(n) calculated as max of
    1. E(n+1) meaning we didn't attend this meeting
    2. 1 + sum (E(n+x) * p(x)) where p(x) is the probability of x being the first meeting we can go to after this meeting ends
  4. memoize

memoization array is 10^4 big, and at max, iterate over 10^4 future meetings....so 10^8 is fast enough. Note that 10^4 is a pretty good hint the runtime is parabolic-ish.

Can easily flip problem to DP by starting with the last meeting, which has E=1, since you always attend it if you can.