CF1156F.Card Bag
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a bag which contains n cards. There is a number written on each card; the number on i-th card is ai.
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 QP where P and Q are non-negative integers and Q=0, P≤Q. Output the value of P⋅Q−1 (mod 998244353).
你有一个装有 n 张卡片的袋子。每张卡片上写有一个数字;第 i 张卡片上的数字为 ai。
你正在玩如下游戏:在每一回合中,你从袋中随机选择并移除一张卡片(袋中所有尚未被移除的卡片被选中的概率相等)。第一回合不发生其他任何事情;但从第二回合起,当你移除一张卡片(设其数字为 x)后,你需要将其与上一回合移除的卡片(设其数字为 y)进行比较。可能的结果如下:
- 若 x<y,游戏立即结束,你失败;
- 若 x=y,游戏立即结束,你获胜;
- 若 x>y,游戏继续进行。
若袋中已无剩余卡片,你失败。被移除的卡片不会放回袋中。
你需要计算在此游戏中获胜的概率。可以证明该概率可表示为 QP 的形式,其中 P 与 Q 是非负整数,且 Q=0,P≤Q。请输出 P⋅Q−1(mod998244353) 的值。
输入格式
The first line contains one integer n (2≤n≤5000) — the number of cards in the bag.
The second live contains n integers a1,a2,…an (1≤ai≤n) — the i-th integer is the number written on the i-th card.
第一行包含一个整数 n(2≤n≤5000)—— 表示袋子中卡片的数量。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 其中第 i 个整数表示第 i 张卡片上写的数字。
输出格式
Print one integer — the probability of winning in this game modulo 998244353.
输出一个整数——该游戏中获胜的概率对 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
说明/提示
In the first test case the probability of winning is 101.
In the second test case the probability of winning is 1.
In the third test case the probability of winning is 0.
In the fourth test case the probability of winning is 41.
在第一个测试用例中,获胜的概率为 101。
在第二个测试用例中,获胜的概率为 1。
在第三个测试用例中,获胜的概率为 0。
在第四个测试用例中,获胜的概率为 41。
输入解题思路,AI测评打分。不知道怎么写?