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

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

Hello codeforces, I want your help in following permutation and combination problem.

We are given an arr of numbers and we want to find the no of ways to put all occurences of second max(arr) to left of the max(arr) and ofcourse all the numbers are different(for eg. 4 4, we can arrange these in two ways). I couldn't solve yesterday's C just because of this, so I wanna learn this now. Thanks and have a good day :)

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

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

There's a purely combinatorial way to do this.

As mentioned in the other comment, if there is more than one maximal element, then the answer is $$$n!$$$.

If there is only one maximal element, and $$$x$$$ second-max elements, then the answer is $$$\frac{n!}{x+1}$$$. We can show this using probabilities; if we permute the array randomly, you are effectively permuting the order of max and second-max. As there are $$$x+1$$$ such numbers, there's a $$$\frac{1}{x+1}$$$ probability that the max ends up after all the second-max numbers.

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

Suppose there are M second max values. Also, let's denote the max value as F and second max value as S. Obviously, the number of ways to create a permutation of length N is factorial(N). When you fix one permutation, the order of S and F will be one of the following. [F S S ... S] [S F S ... S] [S S F ... S] ... [S S S ... F] so, the ways to put F in front of some S will be factorial(N) * M / (M + 1)