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

Автор dimiTree, история, 3 года назад, По-английски

We are given n disjoint, finite sets.

We would like to count the amount of all possible subsets, while having the following restriction: we are only allowed to include a max of one element each out of every of our n disjoint sets.

My initial thought was to count all possible subsets of size {0, 1, ..., n} and sum them up.

Code

There is probably a much more elegant and efficient solution out there.

Feel free to share your ideas!

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

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Link?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Unfortunately this is from a Discrete Math exercise collection. While this may turn out to be a future contest problem, I'm not aware of any concrete link having this exact same problem.

    But as this boils down to the same idea like the problem of counting the number of divisors (lookup the comment from nikilrselvam for explanation). The best link I could provide would be CSES Counting Divisors.

»
3 года назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

If all the sets are pairwise disjoint and $$$s_i$$$ denotes the size of the $$$i^{th}$$$ set, then the number of possible subsets with at most one element from each is $$$\prod_{i=1}^{n} (s_i+1)$$$.

Explanation
Follow-up
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    nikilrselvam thank you very much. I'd give you 100 upvotes if I could.

    Elegant ideas like this, make Competitive Programming really enjoyable and fascinating.