#P10968. 扑克牌
扑克牌
Problem Description
A standard deck of playing cards without jokers consists of cards, divided into suits: hearts, spades, clubs, and diamonds. Each suit has cards with different ranks. Now you are given some cards from these cards. Please compute the number of ways to arrange them into a line such that any two adjacent cards have different ranks.
A card is represented as XY, where X is the rank, one of 2,3,4,5,6,7,8,9,T,J,Q,K,A. Y is the suit, one of S,H,D,C. For example, 2S, 2H, TD, etc.
Input Format
The first line contains an integer , the number of test cases.
Each test case occupies one line. The line first contains an integer , meaning the number of given cards, followed by space-separated strings. Each string has length and represents one card. All cards in the same test case are distinct.
Output Format
For each test case, output one line in the form Case #X: Y. is the test case number starting from . is the number of valid arrangements. Since the answer may be very large, output the value modulo .
5
1 TC
2 TC TS
5 2C AD AC JC JH
4 AC KC QC JC
6 AC AD AS JC JD KD
Case #1: 1
Case #2: 0
Case #3: 48
Case #4: 24
Case #5: 120
Hint
Translated by ChatGPT 5