題目連接:hdu 5045 Contestjavascript

題目大意:一個隊伍有N我的。比賽一共同擁有M道題目,給定一個矩陣。表示每個人答對對應題目的正確率。現在對於每道題。可以派出一名學生參加答題,但是在隨意時刻,隨意兩個學生答題數量不能相差2題以上。php

解題思路:dp[i][s],表示在第i道題,s表示一個二進制狀態,表示哪些人答過題(對應的),2N1=0css

#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 html

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 1、題目原文 In the ACM International Collegiate Programming Contest, each team consist...
本站公眾號
   歡迎關注本站公眾號,獲取更多信息