Count the possible five-card hands for each of nine poker categories, given two fixed cards from a deck with A ranks and B suits.
Medium6CombinatoricsMathImplementationBrute forceNo attempts yetTime limit2sMemory limit512 MBVera has A×B cards. Each card has a rank, an integer between 0 and A−1, and a suit, an integer between 0 and B−1. All cards are distinct. A set of five different cards is a hand.
Every hand falls into exactly one of nine categories numbered 1 through 9. If a hand satisfies the conditions of more than one category, it belongs to the lowest numbered category among them. The rules are:
Vera currently holds two cards with ranks a1, a2 and suits b1, b2. She picks three more cards from the remaining ones and forms a hand with the two she holds. Compute the number of different hands formed this way that belong to each category.
The first line contains the integers A and B (5≤A≤25, 1≤B≤4).
The second line contains the integers a1, b1, a2, b2 (0≤a1,a2≤A−1, 0≤b1,b2≤B−1, (a1,b1)=(a2,b2)).
Print one line with nine integers separated by single spaces. The i-th integer is the number of different hands that belong to category i, so the counts run from straight flush to high card in increasing order of category number.
Let (a,b) denote the card with rank a and suit b.
In the first example Vera holds (1,0) and (3,1). If she picks (3,0), (4,0), (4,1), her hand has two cards of rank 3 and two other cards of rank 4, so it is a two pair. The same hand also satisfies one pair, but two pair has the lower category number, so it counts as a two pair.