Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

We have N persons numbered from 1 to N. Also there are M identical rooms with infinity capacity.

In how many ways we can distribute persons in rooms such that each room contains at least 1 person ?

Two ways A and B are regarded as the same if for any room in A, there exists a room in B that the persons in these two rooms have the same set of numbers. In other words, rooms are indistinguishable.

for example : 2 rooms , 3 persons , ans = 3 : (1)(2,3) , (2)(1,3) , (3)(1,2)

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

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

Pretty sure you're talking about the Stirling numbers of second kind.

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

    thanks so much ...

    Now problem is that I have to answer 10^5 queries of this problem when N is same for all queries but M is different for each query from 1..10^5. ( N is in range 1..10^5 )

    It seems that this numbers need huge time for calculation , how can we reduce it ? or I am wrong ?

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

      Well the answer to you problem (and the ShareCode problem) is that because N is the same you can calculate these Stirling values using the recursive formula and FFT (NTT to be more specific), the modulo number in that problem was so that you could use NTT.

      keyvankhademi, my teammate was the one who solved it, you can ask him for more details ;)

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

      Can you please share the link to the original problem? Thanks!

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

actually you can use this formula

as you can see it can be written as the product of two polynomials and (k - i)n
so you can easily find s(n, k) for a fixed n and all k.

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

    thanks... very nice! congratulations for being the only team who solved it ... :)

    I don't know FFT for programming contests yet ... I have to learn it first ... can you suggest a good resource for learning it ?

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

    I was reading your approach and I noticed that is not a 1-D array that you can easily multiply, it's 2-D so it can't be used. What we can do here is to reformat the formula: so you should use and . So if you have two polynomials, one with coefficients and one with coefficients , then k - th coefficient of their product is indeed s(n, k).

    P.S: Nice approach by the way, inclusion-exclusion principle...

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

Each of N persons to any of M rooms minus cases of N persons in M-1 rooms m^n-m*(m-1)^n

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

    My friend , problem is not as easy as you think ... you must make sure that each room contains at least one person. Also notice that all the rooms are same.