<html>
题目大意:一个队伍有N个人。比赛一共同拥有M道题目,给定一个矩阵。表示每一个人答对对应题目的正确率。如今对于每道题。能够派出一名学生參加答题,可是在随意时刻,随意两个学生答题数量不能相差2题以上。
解题思路:dp[i][s],表示在第i道题,s表示一个二进制状态,表示哪些人答过题(对应的),2N−1=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...- junior19
- 2017-02-09 20:02
- 40
-
hdu 4099 Revenge of Fibonacci 2011 Asia Shanghai Regional Contest
求一个数是第几个斐波那契数的前缀。假设是多个斐波那契数的前缀,则输出最小的那一个。 由于前缀最多40个,所以仅仅需求出每一个斐波那契数的前60位(防止进位误差),用字典树保存前缀。#include<iostream> #include<cstring> using namespace std; struct dictree { struct dictree * child[10]; int ID; }*root; int a[3][61]; char ask[45]; v
- 444878909
- 2012-06-12 11:46
- 59
-
hdu5045 Contest ---- 状态DP
原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=5045 一:原题内容 Problem Description In the ACM Inte...- LaoJiu_
- 2016-05-28 19:03
- 214
-
hdu 5045 Contest(dp)
<a target="_blank" href="http://acm.hdu.edu.cn/showproblem.php- 阿尔萨斯
- 2014-09-28 10:24
- 50
-
HDU-5045 Contest(状压DP)
HDU-5045 Contest 一、题目原文 In the ACM International Collegiate Programming Contest, each team consist...- Summer_via
- 2016-04-28 13:43
- 82
收藏助手
不良信息举报
0条评论