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. IDEA 15 社区版 Maven项目 启动Tomcat调试

    1.在pom下添加Tomcat插件: <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifac ...

  2. 5.4.1 RegExp实例属性

    RegExp的每个实例都具有下列属性,通过这些属性可以取得有关模式的各种信息.        1.global:布尔值,表示是否设置了 g 标志.        2.ignoreCase:布尔值,表示 ...

  3. [转]使用ping钥匙临时开启SSH:22端口,实现远程安全SSH登录管理就这么简单

    原文链接:使用ping钥匙临时开启SSH:22端口,实现远程安全SSH登录管理就这么简单 这个留待后面玩一下,还是有安全隐患,非核心业务 临时用一下可以. 设置防火墙策略时,关于SSH:22访问权限, ...

  4. sourceTree安装与使用

    1,下载并安装 sourceTree http://downloads.atlassian.com/software/sourcetree/windows/SourceTreeSetup_1.6.14 ...

  5. 捕捉小括号获取的内容保存在RegExp的$1 $2..属性中

    ~~~~捕捉小括号获取的内容保存在RegExp的$1 $2..属性中 var reg=/^(-?\d+)(px|pt|em|in)?$/;if(reg.test(svalue)){           ...

  6. NHibernate 的 ID 标识选择器

    在 Hibernate 中,每个对象需要一个标识 ID,通过这个标识 ID 建立对象与数据库中记录的对应关系. Nhibernate 提供了多种方式来建立这个 POID.基于不同的生成策略,可以选择更 ...

  7. HDU 1568 Fibonacci

    题解:首先,对于小于10000的斐波那契数,我们直接计算,当大于10000时,用公式,由于只要输出前四位,所以不用考虑浮点数的问题,算出其取log的结果: tmp=(log(sq5/5)+n*log( ...

  8. JAVA 创建TXT文件,写入文件内容,读取文件内容

    [java]  view plain copy   package com.abin.facade.ws.mail.function; import java.io.BufferedReader; i ...

  9. jQ 操作积累

    1.判断radio是否选中:方式一:var val=$('input:radio[name="sex"]:checked').val(); //(val==null 未选中) 方式 ...

  10. SharePoint2013切换账户身份登录设置

    1. 打开Welcome.ascx文件:C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE ...