AT_abc470_e.Concentration

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

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

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

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

  • Shuffle the 2N2N cards and lay them out face down.
  • Set life to LL and score to 00.
  • Repeat the following until life becomes 00 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 XX written on it.
    • Choose one face-down card on the table, turn it face up, and check the number YY written on it.
    • If X=YX=Y, remove those two cards from the table, and increase the score by XX.
    • If X≠YX\neq Y, turn the two cards face down again, and decrease life by 11.

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 A1,…,ANA_1,\dots,A_N.
  • Let BB be a sequence obtained by choosing a permutation of the length-2N2N sequence (A1,A1,A2,A2,…,AN,AN)(A_1,A_1,A_2,A_2,\ldots,A_N,A_N) uniformly at random.
  • Initially, Takahashi knows none of the values of BB. Once he learns the value of BiB_i, he remembers it completely thereafter.
  • Let life be LL, score be 00, and SS be 1,2,3,…,2N{1,2,3,\ldots,2N}. Takahashi always knows these values.
  • Repeat the following until life becomes 00 or SS becomes empty:
    • Based on the information obtained up to this point, Takahashi chooses an element from SS, and calls it ii.
    • The value of BiB_i is revealed, and Takahashi learns it.
    • Based on the information obtained up to this point (including the value of BiB_i), Takahashi chooses an element from S∖iS\setminus{i}, and calls it jj.
    • The value of BjB_j is revealed, and Takahashi learns it.
    • If Bi=BjB_i=B_j, remove ii and jj from SS, and add BiB_i to the score.
    • If Bi≠BjB_i \neq B_j, decrease life by 11.
  • Takahashi acts optimally to maximize the expected value of the score at the end of the game.

高桥正在玩一种类似于记忆配对游戏的单人纸牌游戏。

共有 2N2N 张卡片。每张卡片正面写有一个数字,背面为空白。
对每个满足 1≤i≤N1 \leq i \leq N 的 ii,恰好有两张卡片上写着 AiA_i。(这些 AiA_i 两两互异。)

高桥使用如下规则用这些卡片进行游戏:

  • 将 2N2N 张卡片随机洗牌,并全部背面朝上摊开。
  • 将 生命值(life) 设为 LL,得分(score) 设为 00。
  • 重复以下步骤,直至生命值变为 00 或桌面上不再剩有卡片:
    • 从桌面上选择一张背面朝上的卡片,将其翻至正面朝上,并查看其上所写的数字 XX。
    • 再从桌面上选择一张背面朝上的卡片,将其翻至正面朝上,并查看其上所写的数字 YY。
    • 若 X=YX = Y,则将这两张卡片从桌面上移除,并将得分增加 XX。
    • 若 X≠YX \neq Y,则将这两张卡片重新翻回背面朝上,并将生命值减 11。

当高桥采取最优策略以最大化游戏结束时的得分时,求游戏结束时得分的期望值。

以下是该游戏更形式化的描述:

  • 高桥知晓下述游戏规则。
  • 高桥知晓 A1,…,ANA_1, \dots, A_N 的值。
  • 设 BB 是由长度为 2N2N 的序列 (A1,A1,A2,A2,…,AN,AN)(A_1,A_1,A_2,A_2,\ldots,A_N,A_N) 的一个均匀随机排列所得的序列。
  • 初始时,高桥对 BB 的所有元素值一无所知;一旦他获知了 BiB_i 的值,此后便永远记住该值。
  • 设生命值为 LL,得分为 00,集合 S={1,2,3,…,2N}S = \{1,2,3,\ldots,2N\}。高桥始终知晓这些值。
  • 重复以下步骤,直至生命值变为 00 或 SS 变为空集:
    • 基于截至目前所获得的所有信息,高桥从 SS 中选择一个元素,记为 ii。
    • BiB_i 的值被揭示,高桥获知该值。
    • 基于截至目前所获得的所有信息(包括刚获知的 BiB_i),高桥从 S∖{i}S \setminus \{i\} 中选择一个元素,记为 jj。
    • BjB_j 的值被揭示,高桥获知该值。
    • 若 Bi=BjB_i = B_j,则将 ii 和 jj 从 SS 中移除,并将 BiB_i 加入得分。
    • 若 Bi≠BjB_i \neq B_j,则将生命值减 11。
  • 高桥采取最优策略,以最大化游戏结束时得分的期望值。

输入格式

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

NN LL
A1A_1 A2A_2 …\dots ANA_N

输入从标准输入中按以下格式给出:

NN LL
A1A_1 A2A_2 …\dots ANA_N

输出格式

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

输出答案。
若您的输出与正确答案的绝对误差或相对误差不超过 10−510^{-5},则视为正确。

输入输出样例

  • 输入#1

    3 2
    1 2 3

    输出#1

    3.8666666667
  • 输入#2

    5 2
    2 3 5 7 101

    输出#2

    17.8560846561
  • 输入#3

    20 10
    10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200

    输出#3

    770.7122293087

说明/提示

Sample 1 Explanation:
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 22 and score 00.
  • Turn card A face up. 33 is written on it.
  • Turn card B face up. 22 is written on it.
  • Since different numbers are written, turn both cards face down again, and decrease life by 11 to 11.
  • Turn card C face up. 33 is written on it.
  • Turn card A face up. 33 is written on it.
  • Since the same number is written, remove both cards from the table, and increase the score by 33 to 33.
  • Turn card D face up. 11 is written on it.
  • Turn card E face up. 22 is written on it.
  • Since different numbers are written, turn both cards face down again, and decrease life by 11 to 00.
  • Since life has become 00, the game ends. The score is 33.

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 33 written on it, based on the fact that 33 was written on the front of card C."

Constraints

  • 1≤N≤2001 \leq N \leq 200
  • 1≤L≤2001 \leq L \leq 200
  • 1≤A1<A2<⋯<AN≤1051 \leq A_1 < A_2 < \dots < A_N \leq 10^5
  • All input values are integers.

样例 1 解释:
游戏可能按如下方式进行(例如)。为区分六张卡片,我们将其分别记为 A、B、C、D、E、F。

  • 游戏初始生命值为 22,得分为 00。
  • 翻开卡片 A,其正面数字为 33。
  • 翻开卡片 B,其正面数字为 22。
  • 由于两张卡片上的数字不同,将两张卡片再次翻回背面,并将生命值减 11 至 11。
  • 翻开卡片 C,其正面数字为 33。
  • 翻开卡片 A,其正面数字为 33。
  • 由于两张卡片上的数字相同,将这两张卡片从桌面上移除,并将得分增加 33 至 33。
  • 翻开卡片 D,其正面数字为 11。
  • 翻开卡片 E,其正面数字为 22。
  • 由于两张卡片上的数字不同,将两张卡片再次翻回背面,并将生命值减 11 至 00。
  • 由于生命值已变为 00,游戏结束。最终得分为 33。

注意:在此序列中,当 Takahashi 刚翻开卡片 C 后,他可立即根据“卡片 C 正面写有数字 33”这一信息,选择翻开另一张已知正面写有 33 的卡片(即卡片 A)。

限制条件

  • 1≤N≤2001 \leq N \leq 200
  • 1≤L≤2001 \leq L \leq 200
  • 1≤A1<A2<⋯<AN≤1051 \leq A_1 < A_2 < \dots < A_N \leq 10^5
  • 所有输入值均为整数。

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

首页