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的点小于其周围的点,编号为.的点至少大于一个其周围的 ...
随机推荐
- 委托与Lambda表达式
~,先不急说委托和Lambda表达式,先看两个例子再说: 1. 通过委托,为一个数字加10,如下代码: class Program { private delegate int JiSuan(int ...
- C++ 之STL priority_queue
priority_queue 对于基本类型的使用方法相对简单.他的模板声明带有三个参数,priority_queue<Type, Container, Functional>Type 为数 ...
- Windows配置Python编程环境
1.安装Python https://www.python.org/ 2.修改环境变量 将安装python的路径加到path路径 3.配置notepad++ a. notepad++/运行/“运行”按 ...
- libuv 错误号UV_ECANCELED 的处理
这个地方有好多的不明白,也没仔细的看懂代码,希望有牛人指点. 先记录几个issue 1. after_write recv many(>10000) ECANCELED in my write_ ...
- css中z-index属性(标签层叠次序)
定义和用法 z-index 属性设置元素的堆叠顺序.拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面. 注释:元素可拥有负的 z-index 属性值. 注释:Z-index 仅能在定位元素上奏 ...
- 什么是RAW?
RAWRAW是一个PHP网站开发系统,使用简单.快捷,核心功能是通过模版组合网站,模版可以自由开发,使开发者不再受传统开发的那种头晕限制,只需要通过填写表单即可完成网站的开发.此外,开发者还可以通过开 ...
- python -- 计算数学题--用程序解决问题1
1.#一个四位数,各位数字互不相同,所有数字之和等于6,并且这个数是11的倍数,#则满足这种要求的四位数有多少个? 代码如下: # -*- coding: UTF-8 -*-import systyp ...
- Grunt.js 上手
Official Site gruntjs.org/docs/getting-started.html 或者看http://tgideas.qq.com/webplat/info/news_versi ...
- QT 获取文件MD5值
/* 方法1 */ QFile theFile(fileNamePath); theFile.open(QIODevice::ReadOnly); QByteArray ba = QCryptogra ...
- poj 1050 To the Max(线性dp)
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...