JPRSプログラミングコンテスト2026#2 (AtCoder Beginner Contest 470)
E
Concentration
AtCoder
⌀ 2096
原题
← DG →

ConcentrationAI (CI翻译)

Problem Statement

Takahashi is playing a solitaire game similar to the memory-matching game.

There are $2N$ cards. A number is written on the front of each card, and nothing is written on the back. For each $i$ satisfying $1 \leq i \leq N$, there are exactly two cards on which $A_i$ is written. (The $A_i$ are pairwise distinct.)

Takahashi plays the game with these cards using the following procedure.

  • Shuffle the $2N$ cards and lay them out face down.
  • Set life to $L$ and score to $0$.
  • Repeat the following until life becomes $0$ or there are no cards left on the table:
  • Choose one face-down card on the table, turn it face up, and check the number $X$ written on it.
    • Choose one face-down card on the table, turn it face up, and check the number $Y$ written on it.
    • If $X=Y$, remove those two cards from the table, and increase the score by $X$.
    • If $X\neq Y$, turn the two cards face down again, and decrease life by $1$.

Find the expected value of the score at the end of the game when Takahashi acts optimally to maximize the score at the end of the game.

Below is a more formal description of the game.

  • Takahashi knows the rules of this game described below.
  • Takahashi knows the values of $A_1,\dots,A_N$.
  • Let $B$ be a sequence obtained by choosing a permutation of the length-$2N$ sequence $(A_1,A_1,A_2,A_2,\ldots,A_N,A_N)$ uniformly at random.
  • Initially, Takahashi knows none of the values of $B$. Once he learns the value of $B_i$, he remembers it completely thereafter.
  • Let life be $L$, score be $0$, and $S$ be $\{1,2,3,\ldots,2N\}$. Takahashi always knows these values.
  • Repeat the following until life becomes $0$ or $S$ becomes empty:
  • Based on the information obtained up to this point, Takahashi chooses an element from $S$, and calls it $i$.
    • The value of $B_i$ is revealed, and Takahashi learns it.
    • Based on the information obtained up to this point (including the value of $B_i$), Takahashi chooses an element from $S\setminus\{i\}$, and calls it $j$.
    • The value of $B_j$ is revealed, and Takahashi learns it.
    • If $B_i=B_j$, remove $i$ and $j$ from $S$, and add $B_i$ to the score.
    • If $B_i \neq B_j$, decrease life by $1$.
  • Takahashi acts optimally to maximize the expected value of the score at the end of the game.

Constraints

  • $1 \leq N \leq 200$
  • $1 \leq L \leq 200$
  • $1 \leq A_1 < A_2 < \dots < A_N \leq 10^5$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N L
A_1 A_2 \dots A_N

Output

Output the answer. Your output will be considered correct if its absolute or relative error from the true answer is at most $10^{-5}$.

{"titleZh":"集中力","bodyZh":"## 题目描述\n\n> 高桥正在玩一种类似于记忆配对游戏的单人游戏。\n\n有 $2N$ 张卡片。每张卡片的正面写有一个数字,背面没有任何内容。对于满足 $1 \\leq i \\leq N$ 的每个 $i$,恰好有两张卡片写着 $A_i$。($A_i$ 两两不同。)\n\n高桥按照以下流程用这些卡片进行游戏。\n\n- 将 $2N$ 张卡片洗匀,背面朝上摆放。\n- 将 生命值 设为 $L$,将 得分 设为 $0$。\n- 重复以下操作,直到生命值变为 $0$ 或桌上没有剩余卡片:\n- 选择桌上一张背面朝上的卡片,将其翻开并查看上面写的数字 $X$。\n - 选择桌上另一张背面朝上的卡片,将其翻开并查看上面写的数字 $Y$。\n - 如果 $X=Y$,则将这两张卡片从桌上移除,并将得分增加 $X$。\n - 如果 $X\\neq Y$,则将这两张卡片重新翻回背面朝上,并将生命值减少 $1$。\n\n假设高桥采取最优策略,使游戏结束时的得分最大,求游戏结束时得分的期望值。\n\n下面给出游戏的更形式化描述。\n\n- 高桥知道下述游戏规则。\n- 高桥知道 $A_1,\\dots,A_N$ 的值。\n- 令 $B$ 为序列 $(A_1,A_1,A_2,A_2,\\ldots,A_N,A_N)$ 的一个长度为 $2N$ 的排列,并且所有排列等概率选取。\n- 初始时,高桥不知道 $B$ 中的任何值。一旦得知 $B_i$ 的值,此后便会一直记住它。\n- 令生命值为 $L$,得分为 $0$,且 $S$ 为集合 $\{1,2,3,\\ldots,2N\\}$。高桥始终知道这些值。\n- 重复以下操作,直到生命值变为 $0$ 或 $S$ 变为空集:\n- 根据目前为止获得的信息,高桥从 $S$ 中选择一个元素,并将其记为 $i$。\n - 揭示 $B_i$ 的值,高桥得知该值。\n - 根据目前为止获得的信息(包括 $B_i$ 的值),高桥从 $S\\setminus\\{i\\}$ 中选择一个元素,并将其记为 $j$。\n - 揭示 $B_j$ 的值,高桥得知该值。\n - 如果 $B_i=B_j$,则从 $S$ 中移除 $i$ 和 $j$,并将 $B_i$ 加到得分中。\n - 如果 $B_i \\neq B_j$,则将生命值减少 $1$。\n- 高桥采取最优策略,使游戏结束时得分的期望值最大。\n\n## 约束条件\n\n- $1 \\leq N \\leq 200$\n- $1 \\leq L \\leq 200$\n- $1 \\leq A_1 < A_2 < \\dots < A_N \\leq 10^5$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入通过标准输入给出,格式如下:\n\ntext\nN L\nA_1 A_2 \\dots A_N\n\n\n## 输出格式\n\n输出答案。\n只要答案与正确答案的绝对误差或相对误差不超过 $10^{-5}$,就会被判定为正确。"}AI (CI翻译)

样例

Input #1
3 2
1 2 3
Output #1
3.8666666667
The game may proceed as follows, for example. To distinguish the six cards, let us call them `A`, `B`, `C`, `D`, `E`, `F`. - Start the game with life $2$ and score $0$. - Turn card `A` face up. $3$ is written on it. - Turn card `B` face up. $2$ is written on it. - Since different numbers are written, turn both cards face down again, and decrease life by $1$ to $1$. - Turn card `C` face up. $3$ is written on it. - Turn card `A` face up. $3$ is written on it. - Since the same number is written, remove both cards from the table, and increase the score by $3$ to $3$. - Turn card `D` face up. $1$ is written on it. - Turn card `E` face up. $2$ is written on it. - Since different numbers are written, turn both cards face down again, and decrease life by $1$ to $0$. - Since life has become $0$, the game ends. The score is $3$. Note that, immediately after turning card `C` face up in this sequence, Takahashi can make the choice of "turning face up card `A`, the other already-known card with $3$ written on it, based on the fact that $3$ was written on the front of card `C`."
Input #2
5 2
2 3 5 7 101
Output #2
17.8560846561
Input #3
20 10
10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200
Output #3
770.7122293087
题目信息
题号
abc470_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。