#P2473. [SCOI2008] 奖励关

    ID: 1485 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划dp2008四川各省省选O2优化状态压缩状压期望

[SCOI2008] 奖励关

Description

You are playing your favorite video game and have just entered a bonus stage. In this stage, the system will randomly drop items kk times in sequence. Each time, you may choose to take the item or not take it (you must decide before the next drop, and an item you skip now cannot be taken later).

There are nn types of items. Each drop is equally likely to be any of the nn types, and all drops are independent. That is, even if the system drops item 11 in the first (k1)(k - 1) drops (which is possible, though very unlikely), the probabilities for the kk-th drop are still all 1n\frac 1 n.

Taking an item of type ii yields pip_i points, but not every item can be taken freely. Item ii has a prerequisite set sis_i. You can take item ii only if every item in sis_i has been taken at least once. If the system drops an item that you currently cannot take, that opportunity is simply lost. Note that pip_i can be negative; however, if it is a prerequisite for many high-scoring items, taking this negative item at a short-term loss may lead to greater long-term gain.

Assuming you follow the optimal strategy, what is the expected total score you can obtain in the bonus stage?

Input Format

The first line contains two integers, the number of drops kk and the number of item types nn.

Lines 22 through (n+1)(n + 1) describe the nn items. On line (i+1)(i + 1), several integers describe item ii: first an integer pip_i, then several distinct integers giving the prerequisites sis_i, and finally an integer 00 marking the end of the line.

Output Format

Output a single real number, the answer, with six digits after the decimal point.

1 2
1 0
2 0

1.500000
6 6
12 2 3 4 5 0
15 5 0
-2 2 4 5 0
-11 2 5 0
5 0
1 2 4 5 0

10.023470

Hint

Constraints

For all test points, it is guaranteed that 1k1001 \leq k \leq 100, 1n151 \leq n \leq 15, and 106pi106-10^6 \leq p_i \leq 10^6.

Translated by ChatGPT 5