CF229E.Gifts

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Once upon a time an old man and his wife lived by the great blue sea. One day the old man went fishing and caught a real live gold fish. The fish said: "Oh ye, old fisherman! Pray set me free to the ocean and I will grant you with n gifts, any gifts you wish!". Then the fish gave the old man a list of gifts and their prices. Some gifts on the list can have the same names but distinct prices. However, there can't be two gifts with the same names and the same prices. Also, there can be gifts with distinct names and the same prices. The old man can ask for n names of items from the list. If the fish's list has p occurrences of the given name, then the old man can't ask for this name of item more than p times.

The old man knows that if he asks for s gifts of the same name, the fish will randomly (i.e. uniformly amongst all possible choices) choose s gifts of distinct prices with such name from the list. The old man wants to please his greedy wife, so he will choose the n names in such a way that he can get n gifts with the maximum price. Besides, he isn't the brightest of fishermen, so if there are several such ways, he chooses one of them uniformly.

The old man wondered, what is the probability that he can get n most expensive gifts. As the old man isn't good at probability theory, he asks you to help him.

从前,有一位老人和他的妻子住在蔚蓝的大海边。一天,老人去钓鱼,捕到了一条真正活生生的金鱼。金鱼说道:“哦,老渔夫啊!请把我放回大海吧,我将赐予你 nn 件礼物,任何你想要的礼物!”接着,金鱼给了老人一份礼物清单及其对应的价格。清单上某些礼物名称可能相同,但价格互不相同;然而,不可能存在两件名称与价格均相同的礼物。此外,也可能存在名称不同但价格相同的礼物。老人可以从清单中挑选 nn 个物品名称(允许重复)。若清单中某名称共出现 pp 次,则老人对该名称的请求次数不得超过 pp 次。

老人知道:若他请求某名称的礼物共 ss 件,则金鱼将从清单中所有具有该名称且价格互不相同的礼物中,等概率地随机选取 ss 件(即在所有满足条件的组合中均匀随机选择)。老人想取悦他贪婪的妻子,因此他会以某种方式选择这 nn 个名称,使得最终获得的 nn 件礼物的总价格尽可能高。此外,老人并非最聪明的渔夫,因此若存在多种能达到最大总价格的选择方式,他将等概率地从中任选一种。

老人不禁思考:他最终恰好获得价格最高的 nn 件礼物的概率是多少?由于老人不擅长概率论,他请你来帮他解答这个问题。

输入格式

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) — the number of the old man's wishes and the number of distinct names in the goldfish's list, correspondingly. Then m lines follow: the i-th line first contains integer k__i (k__i > 0) — the number of distinct prices of gifts with the i-th name, then k__i distinct space-separated integers c__ij (1 ≤ c__ij ≤ 109), the gifts' prices.

It is guaranteed that the sum of all k__i doesn't exceed 1000. It is guaranteed that n is not greater than the total number of the gifts.

第一行包含两个以空格分隔的整数 nn 和 mm(1≤n,m≤10001 \leq n, m \leq 1000),分别表示老人的愿望数量以及金鱼名单中不同名字的数量。接下来是 mm 行:第 ii 行首先包含一个整数 kik_i(ki>0k_i > 0)—— 表示具有第 ii 个名字的礼物的不同价格种类数,然后是 kik_i 个以空格分隔的互不相同的整数 cijc_{ij}(1≤cij≤1091 \leq c_{ij} \leq 10^9),即这些礼物的价格。

保证所有 kik_i 的总和不超过 10001000。同时保证 nn 不超过礼物的总数。

输出格式

On a single line print one real number — the probability of getting n most valuable gifts. The answer will be considered correct if its absolute or relative error does not exceed 10 - 9.

在一行中输出一个实数——获得价值最高的 nn 件礼物的概率。若答案的绝对误差或相对误差不超过 10−910^{-9},则视为正确。

输入输出样例

  • 输入#1

    3 1
    3 10 20 30

    输出#1

    1.000000000
  • 输入#2

    3 2
    1 40
    4 10 20 30 40

    输出#2

    0.166666667

输入解题思路,AI测评打分。不知道怎么写?

首页