306167: CF1156F. Card Bag
Memory Limit:512 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Card Bag
题意翻译
### 题目描述 你有一个装有 $n$ 张卡牌的卡包,卡包中第 $i$ 张卡牌上写有数字 $a_i$。在接下来的每一个回合,你会从卡包中等概率随机抽出一张卡牌,每一回合抽出的卡牌不会重新放回卡包中。 从第二回合开始,每一回合,你需要对这一回合抽出的卡牌的点数 $x$ 和上一次抽出的卡牌的点数 $y$ 进行比较: - 如果 $x < y$,游戏失败并结束; - 如果 $x = y$,游戏胜利并结束; - 如果 $x > y$,游戏继续。 如果某一次抽牌的时候卡包中没有牌,则游戏失败。 你需要求出游戏胜利的概率,对 $998244353$ 取模。 ### 输入格式 第一行一个正整数 $n$ 表示卡牌数量,接下来一行 $n$ 个整数 $a_1,a_2,...,a_n$ 表示卡包中每张卡牌上的数字。 ### 输出格式 输出一行一个整数表示游戏获胜的概率,对 $998244353$ 取模。 ### 数据范围 $2 \leq n \leq 5000$,$1 \leq a_i \leq n$。题目描述
You have a bag which contains $ n $ cards. There is a number written on each card; the number on $ i $ -th card is $ a_i $ . You are playing the following game. During each turn, you choose and remove a random card from the bag (all cards that are still left inside the bag are chosen equiprobably). Nothing else happens during the first turn — but during the next turns, after removing a card (let the number on it be $ x $ ), you compare it with the card that was removed during the previous turn (let the number on it be $ y $ ). Possible outcomes are: - if $ x < y $ , the game ends and you lose; - if $ x = y $ , the game ends and you win; - if $ x > y $ , the game continues. If there are no cards left in the bag, you lose. Cards are not returned into the bag after you remove them. You have to calculate the probability of winning in this game. It can be shown that it is in the form of $ \frac{P}{Q} $ where $ P $ and $ Q $ are non-negative integers and $ Q \neq 0 $ , $ P \le Q $ . Output the value of $ P \cdot Q^{−1} ~(mod ~~ 998244353) $ .输入输出格式
输入格式
The first line contains one integer $ n $ ( $ 2 \le n \le 5000 $ ) — the number of cards in the bag. The second live contains $ n $ integers $ a_1, a_2, \dots a_n $ ( $ 1 \le a_i \le n $ ) — the $ i $ -th integer is the number written on the $ i $ -th card.
输出格式
Print one integer — the probability of winning in this game modulo $ 998244353 $ .
输入输出样例
输入样例 #1
5
1 1 4 2 3
输出样例 #1
299473306
输入样例 #2
2
2 2
输出样例 #2
1
输入样例 #3
5
4 5 1 3 2
输出样例 #3
0
输入样例 #4
4
1 3 4 3
输出样例 #4
748683265