• [BZOJ1076][SCOI2008]奖励关(概率DP)


    Code

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define N 110
    #define db double 
    using namespace std;
    
    int n,m,nd[N],v[N];
    db f[N][1<<16];
    
    inline int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    db DP(int i,int S){
    	if(i>m) return 0;
    	db &tmp=f[i][S];
    	if(tmp+1e9>1e-9) return tmp;
    	tmp=0;
    	for(int j=1;j<=n;++j)
    		if((S|nd[j])==S)
    			tmp+=max(DP(i+1,S),DP(i+1,S|(1<<(j-1)))+v[j]);
    		else tmp+=DP(i+1,S);	
    	tmp/=n;
    	return tmp;
    }
    
    int main(){
    	m=read(),n=read();
    	for(int i=1;i<=n;++i){
    		v[i]=read();
    		for(int x=read();x!=0;x=read()) nd[i]|=(1<<(x-1));
    	}
    	for(int i=0;i<=m;++i)for(int j=0;j<(1<<n);++j)f[i][j]=-2e9;
    	printf("%.6lf
    ",DP(1,0));
    }
    
  • 相关阅读:
    E
    牛客比赛—身体训练
    前缀和例题
    欧拉函数模板
    3.30训练题
    poj1321棋盘问题
    记set学习
    B. K-th Beautiful String
    codeforces1293C
    LightOJ 1370 Bi-shoe and Phi-shoe
  • 原文地址:https://www.cnblogs.com/void-f/p/9129442.html
Copyright © 2020-2023  润新知