状压DP。。

Contest

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 666    Accepted Submission(s): 300

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
 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue> using namespace std; const int maxn=1100; int N,M;
double P[15][maxn]; int num[1100]; int getONE(int x)
{
int ans=0;
while(x)
{
x=x&(x-1);
ans++;
}
return ans;
} void init()
{
for(int i=0;i<=1024;i++)
num[i]=getONE(i);
} double pb[maxn];
bool vis[maxn]; double getMX(int i,int n)
{
double ans=0;
queue<int> q;
memset(vis,0,sizeof(vis));
memset(pb,0,sizeof(pb));
q.push(0);
for(int j=1;j<=n;j++)///第i组任务里的第j个
{
int task=i+j-1;
while(q.empty()!=true)
{
int t=q.front();
if(num[t]>=j) break;
q.pop();
if(num[t]==j-1)
for(int k=0;k<N;k++)
{
if((t&(1<<k))==0)
{
int id=t|(1<<k);
pb[id]=max(pb[id],pb[t]+P[k+1][task]);
ans=max(pb[id],ans);
if(vis[id]==false)
{
vis[id]=true;
q.push(id);
}
}
}
}
}
return ans;
} int main()
{
int T_T,cas=1;
init();
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d%d",&N,&M);
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
scanf("%lf",&P[i][j]);
double ans=0;
for(int i=1;i+N-1<=M;i+=N)///第i组任务
{
getMX(i,N);
ans+=pb[(1<<N)-1];
}
int res=M%N;
if(res) ans+=getMX(M-res+1,res);
printf("Case #%d: %.5lf\n",cas++,ans);
}
return 0;
}

HDOJ 5045 Contest的更多相关文章

  1. HDU 5045 Contest(状压DP)

    Problem Description In the ACM International Collegiate Programming Contest, each team consist of th ...

  2. hdu - 5045 - Contest(国家压缩dp)

    意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...

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

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

  4. HDU 5045 Contest

    pid=5045">主题链接~~> 做题感悟:比赛时这题后来才写的,有点小尴尬.两个人商议着写写了非常久才写出来,I want to Powerful ,I believe me ...

  5. hdu 3342 Legal or Not(拓扑排序) HDOJ Monthly Contest – 2010.03.06

    一道极其水的拓扑排序……但是我还是要把它发出来,原因很简单,连错12次…… 题意也很裸,前面的废话不用看,直接看输入 输入n, m表示从0到n-1共n个人,有m组关系 截下来m组,每组输入a, b表示 ...

  6. hdu 5045 Contest(状态压缩DP)

    题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...

  7. [状压dp]HDU5045 Contest

    题意: n和人做m道题, 每俩人做的题数不能相差一题以上.(也就是每n道题分别由n个人完成)   给n个人分别做m道题的概率, 求完成m题的最大期望 $1\le N \le 10$ 注意!!! fil ...

  8. HDOJ 3415 Max Sum of Max-K-sub-sequence(单调队列)

    因为是circle sequence,可以在序列最后+序列前n项(或前k项);利用前缀和思想,预处理出前i个数的和为sum[i],则i~j的和就为sum[j]-sum[i-1],对于每个j,取最小的s ...

  9. HDOJ 题目3308 LCIS(线段树,区间查询,区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. 【转】Python + Android + Uiautomator自动化测试

    1.首先来介绍下UIAutomator工具 UIAutomator是Android官方推出的安卓应用界面自动化测试工具,是最理想的针对APK进行自动化功能回归测试的利器. 2.UIAutomator测 ...

  2. POJ——3159Candies(差分约束SPFA+前向星+各种优化)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 28071   Accepted: 7751 Descrip ...

  3. HDU——2647Reward(DFS或差分约束)

    Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. 北京集训TEST13——PA(Goodness)

    题目: Description 桌面上放有 n 张卡牌.对于每张卡牌,一面是绿色的,另一面是红色的.卡牌的每一面都标有一个整数.对于卡牌a和卡牌b,卡牌a对卡牌b的好感度为卡牌a绿色面的数与卡牌b红色 ...

  5. Linux 下运行 C++ 程序出现 “段错误(核心已转储)”

    Linux下写C++程序出现“段错误(核心已转储)”的问题: 段错误一般就是指访问的内存超出了系统所给这个程序的内存空间,通常这个值是由gdtr来保存的,他是一个48位的寄存器,其中的32位是保存由它 ...

  6. bat常用命令,转【http://www.cnblogs.com/yplong/archive/2013/04/02/2996550.html】

    1.@它的作用是隐藏它后面这一行的命令本身(只能影响当前行).2.echo中文为“反馈”.“回显”的意思.它其实是一个开关命令,就是说它只有两种状态:打开和关闭.于是就有了echo on和echo o ...

  7. 降雨量 BZOJ 1067

    降雨量 [问题描述] 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意Y<Z<X,Z年的降雨量严格小于X年.例如2002,2003,20 ...

  8. 解决PHP无法接收post超过1000个字段的问题

    今天在做与后台交互的的过程中,发现php对于接收的POST有一个限制,超出1000个字段之后便无法接收,项目要求在不改变PHP配置的情况下通过前端方式解决,通过分析并且网上差一些大牛的资料终于找到了解 ...

  9. msp430项目编程42

    msp430综合项目---无线通信直流电机调速系统42

  10. Post Content_Length exceeds the limit

    2017.12,公司市场专员反馈我在公司开发与维护的iOS包内审系统在上传ipa包文件的时候报错了.经过调试发现原来是因为上传的文件太大导致报错(由下图可知,接收方允许的最大请求内容为128M,但我们 ...