Number of n-element permutations with exactly k inversions
问题 I am trying to efficiently solve SPOJ Problem 64: Permutations. Let A = [a1,a2,...,an] be a permutation of integers 1,2,...,n. A pair of indices (i,j), 1<=i<=j<=n, is an inversion of the permutation A if ai>aj. We are given integers n>0 and k>=0. What is the number of n-element permutations containing exactly k inversions? For instance, the number of 4-element permutations with exactly 1 inversion equals 3. To make the given example easier to see, here are the three 4-element permutations