Problem K. Permutation
时间限制 3000 ms
内存限制 32 MB
In combinatorics a permutation of a set S with N elements is a listing of the elements of S in some order (each element occurring exactly once). There are N! permutations of a set which has N elements. For example, there are six permutations of the set {1,2,3}, namely [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
But Bob think that some permutations are more beautiful than others. Bob write some pairs of integers(Ai, Bi) to distinguish beautiful permutations from ordinary ones. A permutation is considered beautiful if and only if for some i the Ai-th element of it is Bi. We want to know how many permutations of set {1, 2, ...., N} are beautiful.
输入数据
输出数据
For each test case, output the case number first. Then output the number of beautiful permutations in a line.
样例输入
复制
3
3 2
1 1
2 1
3 2
1 1
2 2
4 3
1 1
1 2
1 3
样例输出
复制
Case 1: 4
Case 2: 3
Case 3: 18
$ Mathjax font initiator $