Logo
(追記) (追記ここまで)

4879번 - PERMS 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB40312877.778%

문제

Count the number of permutations that have a specific number of inversions.

Given a permutation a1, a2, a3,..., an of the n integers 1, 2, 3, ..., n, an inversion is a pair (ai, aj) where i < j and ai > aj. The number of inversions in a permutation gives an indication on how "unsorted" a permutation is. If we wish to analyze the average running time of a sorting algorithm, it is often useful to know how many permutations of n objects will have a certain number of inversions.

In this problem you are asked to compute the number of permutations of n values that have exactly k inversions.

For example, if n = 3, there are 6 permutations with the indicated inversions as follows:

123 0 inversions
132 1 inversion (3 > 2)
213 1 inversion (2 > 1)
231 2 inversions (2 > 1, 3 > 1)
312 2 inversions (3 > 1, 3 > 2)
321 3 inversions (3 > 2, 3 > 1, 2 > 1)

Therefore, for the permutations of 3 things

  • 1 of them has 0 inversions
  • 2 of them have 1 inversion
  • 2 of them have 2 inversions
  • 1 of them has 3 inversions
  • 0 of them have 4 inversions
  • 0 of them have 5 inversions
  • etc.

입력

The input consists one or more problems. The input for each problem is specified on a single line, giving the integer n (1 <= n <= 18) and a non-negative integer k (0 <= k <= 200). The end of input is specified by a line with n = k = 0.

출력

For each problem, output the number of permutations of {1, ..., n}with exactly k inversions.

제한

예제 입력 1

3 0
3 1
3 2
3 3
4 2
4 10
13 23
18 80
0 0

예제 출력 1

1
2
2
1
5
0
46936280
184348859235088

힌트

출처

ICPC > Regionals > North America > Rocky Mountain Regional > 2003 Rocky Mountain Regional Contest H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /