A16217 | Jellyfish and Miku
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n + 1$ cities with numbers from $0$ to $n$ , connected by $n$ roads. The $i$ -th $(1 \leq i \leq n)$ road connects city $i-1$ and city $i$ bi-directionally. After Jellyfish flew back to city $0$ , she found out that she had left her Miku fufu in city $n$ .
Each road has a positive integer level of beauty. Denote the beauty of the $i$ -th road as $a_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 $s$ 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 $\frac x s$ , where $x$ is the beauty of the road, reaching the city on the other side of the road.
Jellyfish will start at city $0$ , and she will get only her fufu back when she reaches city $n$ .
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 $m$ .
Find the minimum expected number of days Jellyfish needs to get her fufu back if the beauty of the roads is chosen optimally.
Each road has a positive integer level of beauty. Denote the beauty of the $i$ -th road as $a_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 $s$ 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 $\frac x s$ , where $x$ is the beauty of the road, reaching the city on the other side of the road.
Jellyfish will start at city $0$ , and she will get only her fufu back when she reaches city $n$ .
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 $m$ .
Find the minimum expected number of days Jellyfish needs to get her fufu back if the beauty of the roads is chosen optimally.
输入格式
The first and only line of the input contains two integers $n$ and $m$ ( $1 \leq n \leq m \leq 3000$ ) — the number of the roads and the maximum sum of beauty of the roads.
输出格式
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^{-9}$ . Formally, let your answer be $a$ , and the jury's answer be $b$ . Your answer is considered correct if $\frac{|a-b|}{\max(1,|b|)} \leq 10^{-9}$ .
Your answer will be accepted if the absolute or relative error does not exceed $10^{-9}$ . Formally, let your answer be $a$ , and the jury's answer be $b$ . Your answer is considered correct if $\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]$ . The expected number of days Jellyfish needs to get her fufu back is $5.2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted