Enigma2018

Can someone please explain me the approach to solve this problem

You need to arrange N numbers, and the arrangement must contain a given subsequence of length M. First of all, check if its possible, ie., if all the M numbers are distinct. Then, since the order in which the M numbers appear is fixed, we just need to find the number of ways in which you can put the other N-M numbers in N positions. After that, the remaining M numbers will be placed in the leftover spaces.

The number of ways in which you can put N-M numbers in N positions is Np(N-M) = N!/M!.

1 Like

Suppose you have n=4,m=2 . You can place the remaining 2 elements in 4 * 3 ways. For n=5,m=2 ,you can place the remaining 3 elements in 5 * 4 * 3 ways.Observed some pattern?Rest I’ll leave it to you to know how.
You can refer this


[1]


  [1]: https://www.codechef.com/viewsolution/17053775
1 Like

Access is denied to this code :confused:

If some elements in the m sized array are same then the answer would be zero right ? Else n!/m!

@kunal12 Yes.

Got it… thankyou @hemanth_1 :slight_smile:

1 Like

Who to approach this one from the same contest, help please