Блог пользователя Tornad0

Автор Tornad0, история, 8 лет назад, По-английски

http://mirror.codeforces.com/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

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

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.