Codeforces Beta Round #28 (Codeforces format)

题目链接: http://codeforces.com/contest/28/problem/C

题意:

有 \(n\) 个人,\(m\) 间浴室,每间浴室有\(a[ i ]\)个浴缸,每个人要洗澡的话都要排队,假如一群人进入同一个浴室,他们总倾向于使得最长的队伍最短,现在问你所有队伍中最长的期望?

中文题解:

用状态 \(dp[i][j][k]\) 表示还剩 \(i\) 间浴室,还剩 \(j\) 个人,之前最长队伍的长度为 \(k\) 的期望最长队伍长度。

那么状态转移方程为:

$dp[i][j][k] = \sum_{i=1}{m}\sum_{j=0}{n}\sum_{k=1}{n}\sum_{c=1}{j}(dp[i-1][j-c][max(k, \frac{c+a[i]-1}{a[i]})] * \frac{(i-1)^{j-c}}{ i^j } * C(j, c)) $

其中 \(c\) 是枚举当前去第 \(j\) 间浴室的人数。

那么答案就是 \(dp[m][n][0]\)

时间复杂度:\(O(n^{3}*m)\)

英文题解:

This problem is solved by dynamic programming

Consider the following dynamics: \(dp[i][j][k]\).

\(i\) --- number of not yet processed students,

\(j\) --- number of not yet processed rooms,

\(k\) --- maximum queue in the previous rooms.

The value we need is in state \(dp[n][m][0]\). Let's consider some state \((i, j, k)\) and search through all \(c\) from 0 to \(i\). If \(c\) students will go to \(j\)th room, than a probability of such event consists of factors: \(C_{i}^{c}\) --- which students will go to \(j\)th room.

\((1 / j)^c· ((j - 1) / j)^{i-c}\) --- probability, that \(c\) students will go to \(j\)th room,and the rest of them will go to the rooms from first to \(j - 1\)th.

Sum for all \(ñ\) from 0 to \(i\) values of

\((1 / j)^c· ((j - 1) / j)^{i-c}·C_{i}^{c}· dp[i-c][j-1][mx]\) . Do not forget to update maximum queue value and get the accepted.

代码:

#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int n,m;
int a[56];
double dp[56][56][56];
double C[56][56]; //题解:
//http://www.cnblogs.com/LzyRapx/p/7692702.html int main()
{
cin>>n>>m;
C[0][0] = 1.0;
for(int i=1;i<=55;i++)
{
C[i][0] = 1.0;
for(int j=1;j<=i;j++)
{
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
for(int i=1;i<=m;i++) cin>>a[i];
for(int i=0;i<=n;i++) dp[0][0][i] = i; for(int i=1;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=0;k<=n;k++)
{
for(int c=0;c<=j;c++)
{
int Max = max(k,(c+a[i]-1)/a[i]);
dp[i][j][k] += dp[i-1][j-c][Max] * pow(i-1,j-c) / pow(i,j) * C[j][c];
}
}
}
}
printf("%.10f\n",dp[m][n][0]);
return 0;
}

最新文章

  1. 使用EF取数据库返回的数据
  2. WebApi 通过类名获取类并实例化
  3. expr命令的一些用法
  4. HTTPS基本原理
  5. ubuntu 安装 GCC
  6. HTML 参考手册
  7. Xaml/Xml 实现对象与存储分离
  8. CRM IFRAME 显示地图
  9. DOS下更改编码方式
  10. 在mac本上折腾android 开发环境
  11. 27.编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish 和Dog,定义主类E,在其main方法中分别创建其对象并测试对象的特性。
  12. 我想操作的是利用SqlDataAdapter的几个Command属性(InsertCommand,UpdateCommand,DeleteCommand)来更新数据库
  13. Linux系统开机启动流程
  14. 5.spark弹性分布式数据集
  15. scala时间处理
  16. ed命令
  17. GNU MAKE参考文档
  18. group by having 判断重复的有几条数据
  19. BZOJ.2095.[POI2010]Bridges(最大流ISAP 二分 欧拉回路)
  20. iis6-0 cve-2017-7269 批量验证脚本

热门文章

  1. 今日SGU 5.23
  2. jquery20--animate() : 运动的方法
  3. js插件---画图软件wePaint如何使用(插入背景图片,保存图片,上传图片)
  4. vue的指令在webstrom下报错
  5. js实现 导航移入移出效果
  6. MarkDown study:
  7. JavaScript--数据结构算法之链表
  8. Vue自定义指令实现下拉加载:v-loadmore
  9. fg、bg、jobs、&amp;、 ctrl+z---系统任务
  10. 【例题 8-13 UVA - 11093】Just Finish it up