状压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. [BZOJ4779] [Usaco2017 Open]Bovine Genomics(hash + 二分)

    传送门 网上的题解: 枚举左端点,二分右端点位置,最后所有左端点的答案取最小值 我的题解... 二分答案,枚举左端点,看看是否有解.. 好像和上面是反的,但是思路没问题 过程用hash判重 #incl ...

  2. 基于注解的 Spring MVC(上)

    什么是Spring MVC Spring MVC框架是一个MVC框架,通过实现Model-View-Controller模式来很好地将数据.业务与展现进行分离.从这样一个角度来说,Spring MVC ...

  3. android之总结(一)——原

    1,TextView 中实现跑马灯,需求:文字左边留置一段空白,不需要紧靠在左边:设置android:padding android:padding和android:layout_margin这个地方 ...

  4. 生成PDF文档

    byte[] buffer = context.Response.Clear(); context.Response.ClearHeaders(); context.Response.ClearCon ...

  5. Jmeter中处理json

    我们在做http接口测试的时候,返回的数据都是json串,Jmeter中本身是不支持直接处理json串的,如果要获取到返回结果中指定的值,必须要要通过正则表达式来获取到,正则表达式比较麻烦,写错了就获 ...

  6. SQL入门随笔(上机实验报告)

    <数据定义部分> 一.定义模式和删除模式 a.为用户定义一个模式学生—课程模式 S-T CREATE  SCHEMA  "S-T"  AUTHORIZATION USE ...

  7. P3367 并查集【模板】 洛谷

    https://www.luogu.org/problem/show?pid=3367#sub 题目描述 如题,现在有一个并查集,你需要完成合并和查询操作. 输入输出格式 输入格式: 第一行包含两个整 ...

  8. windows安装RabbitMQ注意事项

    1.首先下载好ERLANG.RabbitMQ安装包,先安装erlang,设置好环境变量,然后再去安装MQ; 2.别人有两个报错: 一:RabbitMQ安装目录中不允许有空格; 二:安装rabbitmq ...

  9. org.dom4j.IllegalAddException: No such namespace prefix: *** is in scope on: org.dom4j.tree.DefaultElement (dom4j写入XML文件,标签中带【:】(冒号)解决办法)

    用dom4j操作写XML文件,标签中含有冒号,会报 org.dom4j.IllegalAddException: No such namespace prefix: *** is in scope o ...

  10. Credit Memo和Debit Memo在AR以及AP中的概念比较

    AR和AP中都有Credit Memo和Debit Memo的概念, 但是其含义和用法完全不一样,比较难懂,现在整理如下:AR中的CreditMemo和DebitMemo是和客户打交道:AR中的Cre ...