bzoj1076: [SCOI2008]奖励关

链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1076

题意:中文题。

分析:期望题,顺着做不好判断可行条件,我们倒着做,设dp[i][j]表示在选择第i次奖励要或不要之前的已有状态为j。因为是等概率,记得/n。最后答案就是dp[1][0]啦。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1000010;
const int MAX=151;
const int MOD1=1000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000009;
const ll INF=10000000010;
typedef double db;
typedef unsigned long long ull;
int f[20],p[20];
db dp[105][33000];
int main()
{
    int i,j,h,n,k,x;
    scanf("%d%d", &k, &n);
    for (i=1;i<=n;i++) {
        scanf("%d", &p[i]);f[i]=0;
        while (scanf("%d", &x)&&x) f[i]|=1<<(x-1);
    }
    for (i=k;i;i--)
        for (j=0;j<(1<<n);j++) {
            dp[i][j]=0;
            for (h=1;h<=n;h++)
            if ((j&f[h])==f[h]) dp[i][j]+=max(dp[i+1][j],dp[i+1][j|(1<<(h-1))]+p[h]);
            else dp[i][j]+=dp[i+1][j];
            dp[i][j]/=n;
        }
    printf("%.6f\n", dp[1][0]);
    return 0;
}


你可能感兴趣的:(bzoj1076: [SCOI2008]奖励关)