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;
}

Codeforces #28 C.Bath Queue (概率dp)的更多相关文章

  1. CodeForces 540D--Bad Luck Island(概率DP)

    貌似竟然是我的第一道概率DP.. 手机码代码真不舒服.... /************************************************ Memory: 67248 KB Ti ...

  2. codeforces 148D Bag of mice(概率dp)

    题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...

  3. CodeForces 24D Broken robot (概率DP)

    D. Broken robot time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. CodeForces - 28C Bath Queue 概率与期望

    我概率期望真是垃圾--,这题搞了两个钟头-- 题意 有\(n\)个人,\(m\)个浴室,每个浴室里有\(a_i\)个浴缸.每个人会等概率随机选择一个浴室,然后每个浴室中尽量平分到每个浴缸.问期望最长排 ...

  5. CodeForces 148D-Bag of mice(概率dp)

    题意: 袋子里有w个白球b个黑球,现在两个人轮流每次取一个球(不放回),先取到白球的获胜,当后手取走一个球时,袋子里的球会随机的漏掉一个,问先手获胜的概率. 分析: dp[i][j]表示袋子中i个白球 ...

  6. Codeforces 148D Bag of mice 概率dp(水

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...

  7. CodeForces 499D. Name That Tune(概率dp)

    It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the followi ...

  8. Codeforces 513G1 513G2 Inversions problem [概率dp]

    转自九野:http://blog.csdn.net/qq574857122/article/details/43643135 题目链接:点击打开链接 题意: 给定n ,k 下面n个数表示有一个n的排列 ...

  9. Codeforces 1156F Card Bag(概率DP)

    设dp[i][j]表示选到了第i张牌,牌号在j之前包括j的概率,cnt[i]表示有i张牌,inv[i]表示i在mod下的逆元,那我们可以考虑转移,dp[i][j]=dp[i-1][j-1]*cnt[j ...

随机推荐

  1. Nagle和Cork

    我觉得这篇讲的不错. http://blog.csdn.net/c_cyoxi/article/details/8673645 Nagle算法的基本定义是任意时刻,最多只能有一个未被确认的小段. 关闭 ...

  2. 基于二叉树和双向链表实现限制长度的最优Huffman编码

    该代码採用二叉树结合双向链表实现了限制长度的最优Huffman编码,本文代码中的权重所有採用整数值表示.http://pan.baidu.com/s/1mgHn8lq 算法原理详见:A fast al ...

  3. AVEVA PDMS Text Tool

    AVEVA PDMS Text Tool eryar@163.com 网上有个文字工具插件,可以在PDMS中创建三维的字母.数字,不过不能创建中文.所以开发一个小工具,可以在PDMS中创建任意文字,如 ...

  4. jquery2.0.3 全部源码

    /*! * Includes Sizzle.js 选择器,独立的库 * http://sizzlejs.com/ */ (function( window, undefined ) { //" ...

  5. js对数组进行操作

    1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  6. linux的vi或vim文件时,怎样消除刚才查找字符串的高亮?

    有时候,自己在通过/查找字符串时,会出现: 但是呢,当你保存,再次进入还是会出现这么花的高亮显示,很令人苦恼. 解决办法 随便,输入没有的字符串,即可解决. 如下 /sssssssssssssssss ...

  7. mvc表单Form提交 --实体

    1.方式1:字段加验证 @model MvcWeb.Models.UserInfo @{ ViewBag.Title = "Add"; } <h2>Add</h2 ...

  8. Sparse Coding: Autoencoder Interpretation

    稀疏编码 在稀疏自编码算法中,我们试着学习得到一组权重参数 W(以及相应的截距 b),通过这些参数可以使我们得到稀疏特征向量 σ(Wx + b) ,这些特征向量对于重构输入样本非常有用. 稀疏编码可以 ...

  9. Codefroces Educational Round 27 (A,B,C,D)

    A. Chess Tourney time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  10. echo---打印变量或输出字符串

    cho命令用于在shell中打印shell变量的值,或者直接输出指定的字符串.linux的echo命令,在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的,因此有必要了解下e ...