QOJ.ac

QOJ

حد الوقت: 5.0 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#17322. 抽牌

الإحصائيات

你正在進行一場單人紙牌遊戲。牌堆共有 $N$ 張牌,每張牌上都寫有一個介於 $0$ 到 $K$ 之間的整數。你將牌堆洗牌後抽出一張牌,這張牌構成你初始的手牌。接著,你透過重複選擇並棄置一張手牌來進行遊戲。每次棄置一張牌時,你從牌堆頂端抽取與該牌上數字相同數量的牌加入手牌(若牌堆中剩餘的牌不足,則將剩餘的牌全部抽走)。如果你抽完了牌堆中所有的牌,即獲得勝利;如果你手牌用盡但牌堆中仍有剩餘的牌,則宣告失敗。給定牌堆的內容,假設所有可能的洗牌方式機率相等,且你採取最佳策略,請問你獲勝的機率是多少?

輸入格式

第一行包含兩個以空格分隔的整數 $N$ 和 $K$,其中 $N$ ($1 \le N \le 1500$) 是牌堆中的牌數,$K$ ($0 \le K \le 3$) 是牌上寫的最大整數。

第二行包含 $K + 1$ 個以空格分隔的整數 $a_i$ ($0 \le a_i \le N$),從 $i = 0$ 開始:表示牌堆中寫有數字 $i$ 的牌的數量。保證 $a_K > 0$ 且所有 $a_i$ 的總和為 $N$。

輸出格式

輸出一個實數:代表你採取最佳策略時獲勝的機率。如果你的答案與評測系統的答案誤差不超過 $10^{-6}$,則視為正確。

範例

範例輸入 1

4 2
2 0 2

範例輸出 1

0.3333333333333333

範例輸入 2

5 1
3 2

範例輸出 2

0.0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.