題目連接:hdu 5045 Contestjavascript
題目大意:一個隊伍有N我的。比賽一共同擁有M道題目,給定一個矩陣。表示每個人答對對應題目的正確率。現在對於每道題。可以派出一名學生參加答題,但是在隨意時刻,隨意兩個學生答題數量不能相差2題以上。php
解題思路:dp[i][s],表示在第i道題,s表示一個二進制狀態,表示哪些人答過題(對應的),2N−1=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;
}
#include<iostream> #include<cstring> using namespace std; struct dictree { struct dictree * child[10]; int ID; }*root; int a[3][61]; char ask[45]; v html
0條評論