最近好懒散QAQ
就是状压DP+概率。。由于顺着推还要计方案数略麻烦,所以就倒着推
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(int i=l;i<=r;i++) 3 #define dec(i,l,r) for(int i=l;i>=r;i--) 4 #define link(x) for(edge *j=h[x];j;j=j->next) 5 #define mem(a) memset(a,0,sizeof(a)) 6 #define inf 1e9 7 #define ll long long 8 #define succ(x) (1<<x) 9 #define NM 16 10 #define nm 100+5 11 using namespace std; 12 int read(){ 13 int x=0,f=1;char ch=getchar(); 14 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 15 while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); 16 return x*f; 17 } 18 int n,m,a[NM],_t,d[succ(NM)]; 19 double f[nm][succ(NM)]; 20 int main(){ 21 freopen("data.in","r",stdin); 22 n=read();m=read(); 23 inc(i,1,m){ 24 a[i]=read(); 25 while(_t=read())d[i]+=succ(_t-1); 26 } 27 _t=succ(m)-1; 28 dec(i,n,1) 29 inc(j,0,_t){ 30 inc(k,1,m) 31 if((d[k]&j)==d[k])f[i][j]+=max(f[i+1][j|succ(k-1)]+a[k],f[i+1][j]); 32 else f[i][j]+=f[i+1][j]; 33 f[i][j]/=m; 34 } 35 // inc(i,1,n){inc(j,0,_t)printf("%.1lf ",f[i][j]);printf("\n");} 36 printf("%.6lf",f[1][0]); 37 return 0; 38 }