CF261B.Maxim and Restaurant

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.

Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (a__i) represents the number of meters the guest is going to take up if he sits at the restaurant table.

Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.

Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.

马克西姆开了一家自己的餐厅!餐厅里有一张超大的桌子,桌子的长度为 pp 米。

今晚马克西姆将举办一场晚宴,共有 nn 位客人会来参加。我们把马克西姆餐厅的客人从 11 到 nn 编号。马克西姆事先知道所有即将前来的客人的体型大小。第 ii 位客人的体型大小 aia_i 表示该客人坐在餐桌旁时所占据的米数。

在晚宴开始前,客人们以某种顺序在餐厅门前排成一列长队。随后马克西姆依次让客人入内。当队列中下一位客人无法再被安排入座时,马克西姆便停止放行。具体来说,若当前已在餐厅内的所有客人体型大小之和,再加上队列中下一位客人的体型大小,其总和超过 pp,则认为该客人“无处可坐”。此时,为避免冒犯这位无座可坐的客人,马克西姆将不再允许队列中任何后续客人入内——即使之后某位客人本可以恰好坐下。

目前马克西姆想知道:对所有 n!n! 种可能的客人排队顺序,客人实际成功入座人数的平均值是多少?请帮助马克西姆计算这个数值。

输入格式

The first line contains integer n (1 ≤ n ≤ 50) — the number of guests in the restaurant. The next line contains integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 50) — the guests' sizes in meters. The third line contains integer p (1 ≤ p ≤ 50) — the table's length in meters.

The numbers in the lines are separated by single spaces.

第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50)—— 餐厅中客人的数量。
第二行包含整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤501 \leq a_i \leq 50)—— 各位客人的身高(单位:米)。
第三行包含一个整数 pp(1≤p≤501 \leq p \leq 50)—— 桌子的长度(单位:米)。

每行中的数字以单个空格分隔。

输出格式

In a single line print a real number — the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.

在一行中输出一个实数——即该问题的答案。若答案的绝对误差或相对误差不超过 10−410^{-4},则视为正确。

输入输出样例

  • 输入#1

    3
    1 2 3
    3

    输出#1

    1.3333333333

说明/提示

In the first sample the people will come in the following orders:

  • (1, 2, 3) — there will be two people in the restaurant;
  • (1, 3, 2) — there will be one person in the restaurant;
  • (2, 1, 3) — there will be two people in the restaurant;
  • (2, 3, 1) — there will be one person in the restaurant;
  • (3, 1, 2) — there will be one person in the restaurant;
  • (3, 2, 1) — there will be one person in the restaurant.

In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3).

在第一个样例中,顾客到来的顺序如下:

  • (1, 2, 3) — 餐厅内将有两人;
  • (1, 3, 2) — 餐厅内将有一人;
  • (2, 1, 3) — 餐厅内将有两人;
  • (2, 3, 1) — 餐厅内将有一人;
  • (3, 1, 2) — 餐厅内将有一人;
  • (3, 2, 1) — 餐厅内将有一人。

总计得到 (2 + 1 + 2 + 1 + 1 + 1) / 6=8 / 6=1.(3)(2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3)。

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

首页