[SCOI2008] Rewards off __ State compression

Source: Internet
Author: User

Description
You are playing your favorite video game and have just entered a reward pass. In this reward Sekiri, the system will randomly throw k k times, each time you can choose to eat or not eat (must be thrown before the next treasure to make a choice, and now decide not to eat the treasures can not eat later). The treasure altogether has n n kinds, the system throws these n n kinds of treasures each time the probability is same and mutually independent. In other words, even if the former k−1 k-1 system all throw treasure 1 (This situation is likely to occur, although the probability is very small), the K K time to throw the probability of each treasure is still 1n \frac{1}{n}. Obtaining the first I species will get Pi p_i, but not every treasure is freely available. The first I species has a prerequisite for the collection of the precious Si s_i. Only when all the treasures in Si s_i have been eaten at least once can they eat the first I treasures (if the system throws a treasure that cannot be eaten at the moment, it loses an opportunity in vain). Note that Pi p_i can be negative, but if it is a prerequisite for many highly prized treasures, the loss of short-term benefits to eat this negative treasure will gain greater long-term benefits. Suppose you take
The optimal strategy, on average, how much you can score in the reward.

Input
The first behavior is two positive integers k K and n N, that is, the number and type of treasures.
The following n-N lines describe a treasure, in which the first integer represents the score,
The following integers, in turn, represent the various prerequisites for the artifact (each treasure number is 1 to n N), ending with 0.
1<=k<=100 1, 1<=n<=15 1, with a score of integers in [ -10^6,10^6].

Output
Outputs a real number that retains six decimal digits, i.e. the score of the average situation under the optimal strategy.

Sample Input
1 2
1 0
2 0

Sample Output
1.500000

HINT

train of thought
State compressed DP, set fi,s F_{i,s} to represent the former i−1 i-1 the type of the treasure before the binary s s when the value of the first I treasures, then can be solved, but there is a problem: sometimes S is not satisfied with the condition , this requires a lot of special sentences. Then another idea: Set Fi,s f_{i,s} to represent the former i−1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.