Problem Description
In the ACM International Collegiate Programming Contest, each team consist of three students. And the teams are given 5 hours to solve between 8 and 12 programming problems. 



On Mars, there is programming contest, too. Each team consist of N students. The teams are given M hours to solve M programming problems. Each team can use only one computer, but they can’t cooperate to solve a problem. At the beginning of the ith hour, they
will get the ith programming problem. They must choose a student to solve this problem and others go out to have a rest. The chosen student will spend an hour time to program this problem. At the end of this hour, he must submit his program. This program is
then run on test data and can’t modify any more. 



Now, you have to help a team to find a strategy to maximize the expected number of correctly solved problems. 



For each problem, each student has a certain probability that correct solve. If the ith student solve the jth problem, the probability of correct solve is Pij .



At any time, the different between any two students’ programming time is not more than 1 hour. For example, if there are 3 students and there are 5 problems. The strategy {1,2,3,1,2}, {1,3,2,2,3} or {2,1,3,3,1} are all legal. But {1,1,3,2,3},{3,1,3,1,2} and
{1,2,3,1,1} are all illegal. 



You should find a strategy to maximize the expected number of correctly solved problems, if you have know all probability
 
Input
The first line of the input is T (1 ≤ T ≤ 20), which stands for the number of test cases you need to solve.



The first line of each case contains two integers N ,M (1 ≤ N ≤ 10,1 ≤ M ≤ 1000),denoting the number of students and programming problem, respectively.



The next N lines, each lines contains M real numbers between 0 and 1 , the jth number in the ith line is Pij .
 
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then a single real number means the maximal expected number of correctly solved problems if this team follow the best strategy, to five digits
after the decimal point. Look at the output for sample input for details.
 
Sample Input
1
2 3
0.6 0.3 0.4
0.3 0.7 0.9
 
Sample Output
Case #1: 2.20000
 
Source
 
dp[i][j]表示攻克了前i个问题j的状态下的最大值。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
const int INF=0x3f3f3f;
int t,n,m;
double dp[1100][1<<10];
double p[10][1100];
void solve()
{
memset(dp,-INF,sizeof(dp));
dp[0][0]=0.0;
for(int i=0;i<m;i++)
{
for(int j=0;j<(1<<n);j++)
{
if(dp[i][j]<0) continue;
for(int k=0;k<n;k++)
{
if(!((1<<k)&j))
{
int tt=(1<<k)|j;
if(tt==(1<<n)-1) tt=0;
dp[i+1][tt]=max(dp[i+1][tt],dp[i][j]+p[k][i]);
// cout<<"11111 "<<dp[i+1][tt]<<endl;
}
}
}
}
}
int main()
{
int cas=1;
scanf("%d",&t);
while(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]);
}
solve();
double ans=0.0;
for(int i=0;i<(1<<n);i++)
ans=max(ans,dp[m][i]);
printf("Case #%d: ",cas++);
printf("%.5f\n",ans);
}
return 0;
}

HDU 5045 Contest(状压DP)的更多相关文章

  1. HDU 4284Travel(状压DP)

    HDU 4284    Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...

  2. HDU 4336 容斥原理 || 状压DP

    状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...

  3. HDU 3001 Travelling ——状压DP

    [题目分析] 赤裸裸的状压DP. 每个点可以经过两次,问经过所有点的最短路径. 然后写了一发四进制(真是好写) 然后就MLE了. 懒得写hash了. 改成三进制,顺利A掉,时间垫底. [代码] #in ...

  4. HDU - 5117 Fluorescent(状压dp+思维)

    原题链接 题意 有N个灯和M个开关,每个开关控制着一些灯,如果按下某个开关,就会让对应的灯切换状态:问在每个开关按下与否的一共2^m情况下,每种状态下亮灯的个数的立方的和. 思路1.首先注意到N< ...

  5. hdu 4114(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4114 思路:首先是floyd预处理出任意两点之间的最短距离.dp[state1][state2][u] ...

  6. [ACM] hdu 5045 Contest (减少国家Dp)

    Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...

  7. HDU 3091 - Necklace - [状压DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  8. HDU 3811 Permutation 状压dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...

  9. HDU 5838 (状压DP+容斥)

    Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...

随机推荐

  1. HtmlAgilityPack --解析Html源码

    最近项目需要从网络上抓取一下数据解析Html源码,奈何正则表达式难写,于是网上搜索找到了“ HtmlAgilityPack”类库,敏捷开发,果然效率非同寻常. 在此做笔记,写下心得,顺便给自己总结一下 ...

  2. PHPExcel 导出

    <?php include '../init.inc.php'; include "../db.inc.php"; /* @func 引入类 */ include ROOT. ...

  3. js后缀判断

    var extension=fileName.substring(fileName.lastIndexOf('.')+1);

  4. JSP页面中包含文件

    在JSP中,主要有3种功能可以将外部内容包含到JSP文档中jsp:include动作. jsp:include动作允许我们在请求期间将其他页面的输出包含进来.它的主要优点是:在被包含的页面发生更改时, ...

  5. UVa1586 Molar mass

    #include <stdio.h> int GetQuantity(char* q, char** p){    int quantity = 0;    while (*q & ...

  6. BZOJ 1997: [Hnoi2010]Planar( 2sat )

    平面图中E ≤ V*2-6.. 一个圈上2个点的边可以是在外或者内, 经典的2sat问题.. ----------------------------------------------------- ...

  7. java 实现 一个账号只能在一个地方登陆,其他地方被下线

    其实方法有很多的,我这献丑了. 使用理解java 四大作用域. 思路:理解java 四大作用域的关键. 第一个地方登陆: 1.得到请求的SessionId 和 登陆的 用户名 2.把SessionId ...

  8. 加装 ImageMagick 性能更佳!

    1. 下载 Download ImageMagick 以此文件ImageMagick-6.9.1-10-Q16-x64-dll-win进行,第二次开发的研发 2. 安装 Install ImageMa ...

  9. 什么是RAW数据源

    RAW数据源 顾名思义,数据源就是数据的源头,怎么理解那? 大家可以把它想象成一个接口,会给我们返回数据,这个数据是动态的. 举个最简单的例子,比如我要在网页中加载出网站的标题,到时候每个页面都要用到 ...

  10. IAR Embedded Workbench for ARM 6.50.6 & 6.60.1 破解补丁

    IAR EWARM 6.50.6 & 6.60.1 破解 破解原理和方法见:http://blog.csdn.net/chivalrys/article/details/8564568 IAR ...