<html>

题目链接:hdu 5045 Contest

题目大意:一个队伍有N个人。比赛一共同拥有M道题目,给定一个矩阵。表示每一个人答对对应题目的正确率。如今对于每道题。能够派出一名学生參加答题,可是在随意时刻,随意两个学生答题数量不能相差2题以上。

解题思路:dp[i][s],表示在第i道题,s表示一个二进制状态,表示哪些人答过题(对应的),2N1=0

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 15;
const int maxm = 2005;
const int maxs = (1<<10) + 5;
const double INF = 0x3f3f3f3f;

int N, M;
double p[maxn][maxm], dp[maxm][maxm];

void init () {
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= M; j++)
            scanf("%lf", &p[i][j]);
    }
}

double solve () {
    int T = 1<<N;
    for (int i = 0; i <= M; i++)
        for (int j = 0; j < T; j++)
            dp[i][j] = -INF;
    dp[0][0] = 0;

    for (int i = 1; i <= M; i++) {
        for (int s = 0; s < T; s++) {
            for (int k = 0; k < N; k++) {
                if (s & (1<<k))
                    continue;
                dp[i][s | (1<<k)] = max(dp[i][s | (1<<k)], dp[i-1][s] + p[k][i]);
            }
        }
        dp[i][0] = dp[i][T-1];
    }

    double ret = 0;
    for (int i = 0; i < T; i++)
        ret = max(ret, dp[M][i]);
    return ret;
}

int main () {
    int cas;
    scanf("%d", &cas);
    for (int kcas = 1; kcas <= cas; kcas++) {
        init();
        printf("Case #%d: %.5lf\n", kcas, solve());
    }
    return 0;
}
版权声明:本文为博主原创文章。未经博主同意不得转载。 举报
  • 本文已收录于下面专栏:

相关文章推荐

HDU5045:Contest(状压dp)

reference:http://blog.csdn.net/stay_accept/article/details/51232891 Contest Time Limit: 2000/100...

hdu 4099 Revenge of Fibonacci 2011 Asia Shanghai Regional Contest

求一个数是第几个斐波那契数的前缀。假设是多个斐波那契数的前缀,则输出最小的那一个。 由于前缀最多40个,所以仅仅需求出每一个斐波那契数的前60位(防止进位误差),用字典树保存前缀。

#include&lt;iostream&gt; #include&lt;cstring&gt; using namespace std; struct dictree { struct dictree * child[10]; int ID; }*root; int a[3][61]; char ask[45]; v

hdu5045 Contest ---- 状态DP

原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=5045 一:原题内容 Problem Description In the ACM Inte...

hdu 5045 Contest(dp)

<a target="_blank" href="http://acm.hdu.edu.cn/showproblem.php

HDU-5045 Contest(状压DP)

HDU-5045 Contest 一、题目原文 In the ACM International Collegiate Programming Contest, each team consist...
  • 微博
    微信
    QQ
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多仅仅同意输入30个字)

posted @ 2017-08-17 09:16  lytwajue  阅读(159)  评论(0编辑  收藏  举报