HDU 5045 Contest(状压DP)
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
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 .
after the decimal point. Look at the output for sample input for details.
1
2 3
0.6 0.3 0.4
0.3 0.7 0.9
Case #1: 2.20000
#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)的更多相关文章
- HDU 4284Travel(状压DP)
HDU 4284 Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...
- 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表示 ...
- HDU 3001 Travelling ——状压DP
[题目分析] 赤裸裸的状压DP. 每个点可以经过两次,问经过所有点的最短路径. 然后写了一发四进制(真是好写) 然后就MLE了. 懒得写hash了. 改成三进制,顺利A掉,时间垫底. [代码] #in ...
- HDU - 5117 Fluorescent(状压dp+思维)
原题链接 题意 有N个灯和M个开关,每个开关控制着一些灯,如果按下某个开关,就会让对应的灯切换状态:问在每个开关按下与否的一共2^m情况下,每种状态下亮灯的个数的立方的和. 思路1.首先注意到N< ...
- hdu 4114(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4114 思路:首先是floyd预处理出任意两点之间的最短距离.dp[state1][state2][u] ...
- [ACM] hdu 5045 Contest (减少国家Dp)
Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...
- HDU 3091 - Necklace - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 3811 Permutation 状压dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...
- HDU 5838 (状压DP+容斥)
Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...
随机推荐
- solr6环境搭建
1.下载并安装jdk1.8,配置环境变量 2.下载并安装tomcat8(8以上) 3.下载solr源码,转变部署solr a)[solr-6.2.0\server\solr-webapp]下的weba ...
- mac上搭建svn服务器
1.terminal 执行svnadmin create 库地址/库名,生成的即为svn库根地址. 2.修改对应目录下conf/svnserve.conf文件: anon-access = read ...
- https tomcat 证书搭建
首先生成证书说明 keytool -genkey -alias castest -keyalg RSA -keystore c:/keys/caskey 先让输入密码,密码必须记住,下面会用到 其中“ ...
- JVM报错提示
持久代被占满 异常:java.lang.OutOfMemoryError: PermGen space 说明: Perm空间被占满.无法为新的class分配存储空间而引发的异常.这个异常以前是没有的, ...
- (IOS)关于Xcode的架构(Architectures)设置
首先来了解一下Architectures中几个参数的含义 ARMv6:ARM11内核用于iPhone2G和iPhone3G中的架构 ARMv7:modern ARM内核用于iPhone3GS和iPho ...
- js函数预编译和声明语句被提升问题小结
<!DOCTYPE html><html><head></head><body><script>//-------------- ...
- ISO14443 ISO15693 ISO18000
[提要]射频标签的通信标准是标签芯片设计的依据,目前国际上与RFID相关的通信标准主要有:ISO/IEC 18000标准(包括7个部分,涉及125KHz, 13.56MHz, 433MHz, 860- ...
- Google日历添加农历、节日和天气插件(步骤)
Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...
- 找到了解决Elite多媒体键失效的问题
首先抛弃itouch这个东西,google了一下,官方没有解决方案. 其次就是找第三方软件把这些快捷键重新定义,同样google了一下,发现了一个叫做hot keyboard的东西,试验了一下,可以识 ...
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...