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

6913번 - Constrained Permutations 다국어

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

문제

A permutation on the numbers 1,ドル 2, \dots, n$ is a linear ordering of the numbers. For example, there are 6ドル$ permutations of the numbers 1,ドル 2, 3$. They are 123ドル,ドル 132ドル,ドル 213ドル,ドル 231ドル,ドル 312ドル$ and 321ドル$. Another way to think of it is removing $n$ disks numbered 1ドル$ to $n$ from a bag (without replacement) and recording the order in which they were drawn out.

Mathematicians (and other smart people) write down that there are $n! = n \times (n-1) \dots 3 \times 2 \times 1$ permutations of the numbers 1,ドル \dots, n$. We call this "$n$ factorial."

For this problem, you will be given an integer $n$ $(1 \le n \le 9)$ and a series of $k$ $(k \ge 0)$ constraints on the ordering of the numbers. That is, you will be given $k$ pairs $(x,y)$ indicating that $x$ must come before $y$ in the permutation.

You are to output the number of permutations which satisfy all constraints.

입력

Your input will be $k + 2$ lines. The first line will contain the number $n$. The second line will contain the integer $k,ドル indicating the number of constraints. The remaining $k$ lines will be pairs of distinct integers which are in the range 1,ドル \dots, n$.

출력

Your output will be one integer, indicating the number of permutations of 1,ドル \dots, n$ which satisfy the $k$ constraints.

제한

예제 입력 1

3
2
1 2
2 3

예제 출력 1

1

예제 입력 2

4
2
1 2
2 1

예제 출력 2

0

예제 입력 3

4
2
1 2
2 3

예제 출력 3

4

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2003 > CCO 2003 4번

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

출처

대학교 대회

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

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