CF1874D.Jellyfish and Miku

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are n+1n + 1 cities with numbers from 00 to nn, connected by nn roads. The ii-th (1≤i≤n)(1 \leq i \leq n) road connects city i−1i-1 and city ii bi-directionally. After Jellyfish flew back to city 00, she found out that she had left her Miku fufu in city nn.

Each road has a positive integer level of beauty. Denote the beauty of the ii-th road as aia_i.

Jellyfish is trying to find her fufu. Because of her poor sense of direction, she doesn't know which way to go. Every day, she randomly chooses a road connected to the city she currently is in and traverses it. Let ss be the sum of the beauty of the roads connected to the current city. For each road connected to the current city, Jellyfish will traverse the road with a probability of xs\frac x s, where xx is the beauty of the road, reaching the city on the other side of the road.

Jellyfish will start at city 00, and she will get only her fufu back when she reaches city nn.

You want to choose the beauty of the roads such that the expected number of days Jellyfish takes to find her fufu will be the minimum possible. However, due to limited funding, the sum of beauties of all roads must be less than or equal to mm.

Find the minimum expected number of days Jellyfish needs to get her fufu back if the beauty of the roads is chosen optimally.

共有 n+1n + 1 座城市,编号从 00 到 nn,由 nn 条道路连接。第 ii 条道路(1≤i≤n1 \leq i \leq n)双向连接城市 i−1i-1 和城市 ii。在 Jellyfish 飞回城市 00 后,她发现自己的 Miku fufu 被遗落在了城市 nn。

每条道路都有一个正整数的“美丽值”。记第 ii 条道路的美丽值为 aia_i。

Jellyfish 正在寻找她的 fufu。但由于方向感极差,她不知道该往哪个方向走。每天,她会随机选择一条与当前所在城市相连的道路,并沿该道路行走。设 ss 为与当前城市相连的所有道路的美丽值之和;对每条与当前城市相连的道路,Jellyfish 沿该道路行走的概率为 xs\frac{x}{s},其中 xx 是该道路的美丽值,行走后她将到达该道路另一端的城市。

Jellyfish 从城市 00 出发,仅当她抵达城市 nn 时,才能取回她的 fufu。

你希望为各条道路分配美丽值,使得 Jellyfish 找回 fufu 所需的期望天数最小。然而,由于经费有限,所有道路的美丽值之和不得超过 mm。

若以最优方式设定各条道路的美丽值,求 Jellyfish 取回 fufu 所需的最小期望天数。

输入格式

The first and only line of the input contains two integers nn and mm (1≤n≤m≤30001 \leq n \leq m \leq 3000) — the number of the roads and the maximum sum of beauty of the roads.

输入仅有一行,包含两个整数 nn 和 mm(1≤n≤m≤30001 \leq n \leq m \leq 3000)—— 分别表示道路的数量和道路美丽值之和的最大值。

输出格式

Output the minimum expected number of days Jellyfish needs to get her fufu back if the beauty of the roads is chosen optimally.

Your answer will be accepted if the absolute or relative error does not exceed 10−910^{-9}. Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a-b|}{\max(1,|b|)} \leq 10^{-9}.

输出 Jellyfish 在道路美观度被最优选择的情况下,取回她的 fufu 所需的最小期望天数。

若你的答案的绝对误差或相对误差不超过 10−910^{-9},则该答案将被接受。形式化地说,设你的答案为 aa,评测组的答案为 bb,当且仅当 ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a-b|}{\max(1,|b|)} \leq 10^{-9} 时,你的答案被视为正确。

输入输出样例

  • 输入#1

    3 8

    输出#1

    5.200000000000
  • 输入#2

    10 98

    输出#2

    37.721155173329

说明/提示

In the first example, the optimal assignment of beauty is a=[1,2,5]a=[1, 2, 5]. The expected number of days Jellyfish needs to get her fufu back is 5.25.2.

在第一个例子中,美感的最优分配为 a=[1,2,5]a=[1, 2, 5]。Jellyfish 取回她毛绒玩具所需的期望天数为 5.25.2。

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

首页