# bzoj 1076 状态压缩最优期望

dp[i][s] 还剩i次掉落机会,前k-i次已经选择了s的物品,那么接下来最优期望得多少分.

 1 /**************************************************************
2     Problem: 1076
3     User: idy002
4     Language: C++
5     Result: Accepted
6     Time:1144 ms
7     Memory:26660 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #define max(a,b) ((a)>(b)?(a):(b))
12 #define K 101
13 #define N 15
14
15 int n, k;
16 int a[N], r[N], bound;
17 double dp[K][1<<N];
18
19 int main() {
20     scanf( "%d%d", &k, &n );
21     for( int i=0,p; i<n; i++ ) {
22         scanf( "%d", a+i );
23         while(1) {
24             scanf( "%d", &p );
25             if( p==0 ) break;
26             r[i] |= 1<<(p-1);
27         }
28     }
29     bound = (1<<n)-1;
30     for( int i=1; i<=k; i++ ) {
31         for( int s=0; s<=bound; s++ ) {
32             dp[i][s] = 0.0;
33             for( int j=0; j<n; j++ ) {
34                 if( (s & r[j]) == r[j] ) {
35                     double v1 = a[j]+dp[i-1][s|(1<<j)];
36                     double v2 = dp[i-1][s];
37                     dp[i][s] += max( v1, v2 );
38                 } else {
39                     dp[i][s] += dp[i-1][s];
40                 }
41             }
42             dp[i][s] /= n;
43         }
44     }
45     printf( "%.6lf\n", dp[k][0] );
46 }
View Code

posted @ 2015-06-16 17:11  idy002  阅读(250)  评论(0编辑  收藏  举报