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

$1\le N \le 10$

注意!!! fill dp 的地方!  [0, m]  所以要 m+1 !!

 #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
typedef long long LL;
typedef long double LD;
#define pi acos(-1.0)
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
typedef pair<int, int> PI;
typedef pair<int, PI> PP;
#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//LL quick(LL a, LL b){LL ans=1;while(b){if(b & 1)ans*=a;a=a*a;b>>=1;}return ans;}
//inline int read(){char ch=' ';int ans=0;while(ch<'0' || ch>'9')ch=getchar();while(ch<='9' && ch>='0'){ans=ans*10+ch-'0';ch=getchar();}return ans;}
//inline void print(LL x){printf(LLD, x);puts("");}
//inline void read(int &x){char c = getchar();while(c < '0') c = getchar();x = c - '0'; c = getchar();while(c >= '0'){x = x * 10 + (c - '0'); c = getchar();}} double mp[][];
double dp[<<][];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t, ca=;
scanf("%d", &t);
while(t--)
{
int n, m;
scanf("%d%d", &n, &m);
for(int i=;i<n;i++)
for(int j=;j<m;j++)
scanf("%lf", &mp[i][j]);
printf("Case #%d: ", ca++);
for(int i=;i<(<<n);i++)
fill(dp[i], dp[i]+m+, -);
// memset(dp, -1, sizeof(dp));
dp[][]=;
for(int i=;i<m;i++)
for(int s=;s<(<<n);s++)
{
if(dp[s][i]<)
continue ;
for(int j=;j<n;j++)
if(!((<<j) & s)) // 第j个人没做
if(((<<j) | s)==((<<n)-)) // n个人 都做了 则清空 进行下一轮
dp[][i+]=max(dp[][i+], dp[s][i]+mp[j][i]);
else
dp[(<<j) | s][i+]=max(dp[(<<j) | s][i+], dp[s][i]+mp[j][i]);
}
double ans=;
for(int i=;i<=(<<n)-;i++)
ans=max(ans, dp[i][m]);
printf("%.5lf\n", ans);
}
return ;
}

HDOJ 5045

[状压dp]HDU5045 Contest的更多相关文章

  1. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...

  2. Atcoder Regular Contest 093 D - Dark Horse(组合数学+状压 dp)

    Atcoder 题面传送门 & 洛谷题面传送门 常规题,简单写写罢((( 首先 \(1\) 的位置是什么不重要,我们不妨钦定 \(1\) 号选手最初就处在 \(1\) 号位置,最后答案乘个 \ ...

  3. HDUOJ Clear All of Them I 状压DP

    Clear All of Them I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Oth ...

  4. 状压dp Codeforces Beta Round #8 C

    http://codeforces.com/contest/8/problem/C 题目大意:给你一个坐标系,给你一个人的目前的坐标(该坐标也是垃圾桶的坐标),再给你n个垃圾的坐标,这个人要捡完所有的 ...

  5. AC Challenge(状压dp)

    ACM-ICPC 2018 南京赛区网络预赛E: 题目链接https://www.jisuanke.com/contest/1555?view=challenges Dlsj is competing ...

  6. B - 集合选数 (状压DP)

    题目链接:https://cn.vjudge.net/contest/281960#problem/B 题目大意:中文题目 具体思路: 我们通过构造矩阵, x , 3x,9x,27x 2x,6x,18 ...

  7. CCPC-Wannafly Winter Camp Day3 Div1 - 精简改良 - [生成树][状压DP]

    题目链接:https://zhixincode.com/contest/14/problem/D?problem_id=206 样例输入 1  5 5 1 2 1 1 3 1 2 4 1 2 5 1 ...

  8. CH0103最短Hamilton路径 & poj2288 Islands and Brigdes【状压DP】

    虐狗宝典学习笔记: 取出整数\(n\)在二进制表示下的第\(k\)位                                                    \((n >> ...

  9. ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds      Me ...

随机推荐

  1. Azure Redis Cache作为ASP.NET Session状态提供程序

    从上一篇博客<使用Azure Redis Cache>我们已经可以创建并使用Redis Cache为我们服务了. 作为Web开发者,我们都知道Session状态默认是保存在内存中的,它的优 ...

  2. MySQL支持多种存储引擎

    MySQL的强大之处在于它的插件式存储引擎,我们可以基于表的特点使用不同的存储引擎,从而达到最好的性能. MySQL有多种存储引擎:MyISAM.InnoDB.MERGE.MEMORY(HEAP).B ...

  3. html-----018----HTML Web Server/HTML URL 字符编码

    HTML Web Server 如果希望向世界发布您的网站,那么您必须把它存放在 web 服务器上. 托管自己的网站 在自己的服务器上托管网站始终是一个选项.有几点需要考虑: 硬件支出 如果要运行“真 ...

  4. 使用jQuery调用ASP.NET WebService的简易教程

    鉴于使用Javascript调用Web Service配置略麻烦,所以记录一下. 1. 新建一个Web服务(WebService.asmx) 2. 取消注释// [System.Web.Script. ...

  5. 简单jquery 鼠标悬停提示效果

    记得自己引入jq插件哦~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  6. C++里的int 和string类型相互转换

    C++不像Java和C#一样在进行数据类型转换时直接调用一些类方法就可以了,使用起来很简单. 一个很简单的例子就是string str=“D:\\”+1+“.txt”;这在Java或者C#里面是可以自 ...

  7. 第3条:用私有构造器或者枚举类型强化Singleton属性

    Singleton是指仅仅被实例化一次的类.通过被用来代表那些本质上唯一的系统组件,比如窗口管理器或者文件系统. 在http://www.cnblogs.com/13jhzeng/p/5256424. ...

  8. resin的简单介绍和使用

    1.resin是一款应用服务器(application server),它自身也包含一款支持Http1.1协议的WEB服务器(web server),它也可以和其他的web服务器一起工作如IIS和Ap ...

  9. 转载 shell sort

    http://blog.sina.com.cn/s/blog_6d09b5750100x6zg.html 首先是shell排序实现多列排序,这里添加竖线以作分割,如下文件test: a|gggg|4| ...

  10. GCC编译器入门

    GCC(GNU Compiler Collection,GNU编译器套件),是由 GNU 开发的编程语言编译器.它是以GPL许可证所发行的自由软件,也是 GNU计划的关键部分.GCC原本作为GNU操作 ...