BZOJ1076[SCOI2008] Rewards off __ probability and expectation

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-Times treasures,
Every time you choose to eat or not eat (you must make a choice before throwing the next treasure, and now decide not to eat the treasures can not eat later).
There are a total of n kinds of treasures, the system every time the probability of throwing these n treasures are the same and independent of each other. In other words, even the former k-1 system throws a treasure 1 (
This situation is likely to occur, although the probability is very small, the K-time to throw the probability of each treasure is still 1/n. Get the first I kind of treasures will get pi
Points, but not every treasure is free to get. The first kind treasures have a prerequisite treasure set SI. Only when all the treasures in Si have been eaten at least
Once, can eat the first kind of treasures (if the system throws a currently cannot eat treasures, equal to lose a chance in vain). Note that PI can be
To be negative, but if it is the premise of many highly divided treasures, the loss of short-term benefits to eat this negative treasure will gain greater long-term benefits. Suppose you
Take the optimal strategy and how much you can score on the average in the award. Input

The first behavior is two positive integers k and n, that is, the number and type of treasures. The following n lines describe a treasure, in which the first integer represents the score, with
The integers in turn represent the artifacts (each treasure numbered 1 to N), ending with 0. 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

"Scale of data"

1<=k<=100,1<=n<=15, the score is an integer in [ -10^6,10^6].

DP F[i][j] For the first time the desired transfer of the current state of J is F[i][j]+=max (f[i+1][j| ( 1<< (L-1))]+v[l],f[i+1][j])/n;

That is, select or not to transfer in turn can make F[I][J] This state will only be counted 1 times and will appear repeat if the optimal DP structure is not problematic but in the recursive or expected such models will have problems the final answer is F[1][0]

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const INT maxn=1<<17;
Double F[110][MAXN];
int s[20];
int v[20];
int main () {
    //freopen ("a.in", "R", stdin);
    Freopen ("A.out", "w", stdout);
    int n,k;
    scanf ("%d%d", &k,&n);
    int x;
    for (int i=1;i<=n;i++) {
        scanf ("%d", &v[i]);
        scanf ("%d", &x);
        while (x!=0) {
            s[i]|= (1<< (x-1));
            scanf ("%d", &x);
        }
    int top= (1<<n)-1;
    for (int i=k;i>=1;i--) {for
        (int j=0;j<=top;j++) {for
            (int l=1;l<=n;l++) {
                if (s[l]&j) ==s [l])
                    F[i][j]+=max (f[i+1][j| ( 1<< (L-1))]+v[l])/double (n), f[i+1][j]/double (n));
                else f[i][j]+=f[i+1][j]/double (n);
    }} printf ("%.6lf\n", F[1][0]);
return 0;
}


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.