HDU 5045 Contest 期望+状压dp 2014 ACM/ICPC Asia Regional Shanghai Online

题意:

给定n个人 m个题目

下面n*m的矩阵表示每个人解出每道题的概率


我们可以得到一个模长为m的集合{1,2,3,1,2}

代表每道题是谁解出的。

有众多集合,且获得这个集合有一个期望,求期望最大的那个集合 ( 的期望值是多少)

一个限制: 对于集合 {1,1,2,3,1} 这样是不合法的(即从[1,n]题必须是1-n的排列,然后[n+1, 2n]题也是一个排列)

然后状压dp

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int M= 1000 +2;
const int N= 10+2;
const int S= (1 << 10) + 10;

double d[M][S], p[N][M];
int main() {
    int cas, mx, n, m, to;
    scanf("%d", &cas);
    for(int T= 1; T<= cas; ++T) {
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                scanf("%lf", &p[i][j]);

        mx = (1 << n) - 1;
        memset(d, 0, sizeof d);
        d[0][0] = 0;
        for (int i = 0; i < m; ++i) {
            int s = (1 << (i % n)) - 1;
            while (s < mx) {
                int x = s & -s;
                int y = s + x;
                for (int k = 0; k < n; ++k)
                    if (!(s >> k & 1)) {
                        to = s | (1 << k);
                        if (to == mx)
                            to = 0;
                        d[i + 1][to] = max(d[i + 1][to], d[i][s] * (1.0 - p[k][i]) + (d[i][s] + 1) * p[k][i]);
                    }
                if (s == 0) break;
                s = ((s & ~y) / x >> 1) | y;
            }
        }
        double ans = 0;
        for (int i = 0; i < mx; ++i)
            ans = max(ans, d[m][i]);

        printf("Case #%d: %.5f\n", T, ans);
    }
    return 0;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值