Tornad0's blog

By Tornad0, history, 8 years ago, In English

http://codeforces.net/problemset/problem/698/C

Hi codeforces, though read the tutorial, I still don't understand it. Please anyone explain how to solve it in detail?why we can look backwards? What is the idea?

Btw, what math should I know to understand it?(i can know the dp,bitmask)

Thank you:D

  • Vote: I like it
  • -5
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
Rev. 2   Vote: I like it +10 Vote: I do not like it

consider the choosing sequence from beginning, a1, a2, a3, .. an, now let set S containing the k elements in the cache.
let's see what S actually contains. Since S contains most recently chosen k elements, we can look backward from an and the first k different elements form S.
so event "S contains b1, b2,.. bk"
equals to
event "the last k different elements in the choosing sequence consist of b1, b2, .. bk".
And since prob(a1, a2, .., an) = prob(an, a(n-1),.., a1)
so its probability also equal to
the event "the first k different elements in the choosing sequence consist of b1,b2,..bk"
and this can be calculated easily using dp.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    I feel grateful to tinytiny and Tornad0