#P10328. [UESTCPC 2024] 卡牌游戏
[UESTCPC 2024] 卡牌游戏
Problem Description
Li Hua has a deck of cards. Each card has three attributes: color, number, and value. The color of each card can be represented by an integer in , and similarly, each card also has a number that is an integer in . Based on different numbers and colors, these cards are divided into types.
For convenience, define that the type ID of a card with color and number is . In the deck, there are cards of type , and the value of each card of type is .
At the beginning, Li Hua has an empty hand and an initial score of . Li Hua will play for rounds. At the start of each round, Li Hua randomly draws one card from the remaining cards in the deck, and each remaining card has an equal probability of being drawn. Next, if the hand contains any card whose number or color is the same as the drawn card, then Li Hua returns all cards in the hand that satisfy the above condition, together with the drawn card, back into the deck. Otherwise, the drawn card is placed into the hand.
After each round ends, Li Hua's score increases by the sum of the values of all cards currently in the hand. Please compute the expected total score after rounds, and output it modulo .
Input Format
The first line contains two positive integers , representing the number of colors and numbers, and the number of rounds.
The second line contains integers , representing the number of cards of each type in the deck.
The third line contains integers , representing the score value of each type of card.
The testdata guarantees that the situation where all cards can be placed into the hand at the same time will not occur, and .
Output Format
Output one integer on one line, representing the expected total score after rounds.
2 2
1 1 1 1
2 1 1 1
582309208
2 4
1 2 3 4
4 3 2 1
570601408
Hint
For the first sample, the correspondence between the final score and its probability is as follows.
| Score | |||||
|---|---|---|---|---|---|
| Probability | |||||
The expected score is .
For the second sample, the expected score is .
Translated by ChatGPT 5