CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B
题目大意:给定n个数a1…an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a3…+ai,问满足Si<=p的i的最大值的期望.(p<=50)
(大意来自于http://www.cnblogs.com/liu-runda/p/6253569.html)
我们知道,全排列其实等价于我们一个一个地等概率地向一个序列里面插入数值
所以我们可以这么看这道题:
现在有n个数,有n个盒子,等概率地把这些数放入盒子,求Si<=p的max[i]的期望
我们考虑每个盒子对于答案的贡献
如果第一个盒子保存下来了,那么它的贡献就是p(保存下来的概率)
所以我们只需要计算每个盒子保存下来的概率就可以了
我们又发现:如果第i个盒子保存下来了,那么1~(i-1)的盒子一定都保存下来了
不然第i个盒子就不可能保存下来,原文中:
Maxim doesn't let any other guest in the restaurant
even if one of the following guests in the queue would have fit in at the table.
起到了关键作用
所以我们定义f[i][j][k]表示在前i个数中随机的把数放到盒子里
前j个盒子被放满且前j个盒子中的数之和为k的情况出现的概率
那么我们有f[i][j][k] = f[i-1][j][k]*(1 - (j/i)) + f[i-1][j-1][k - a[i]]*(j/i)
则ans = sigma{f[n][i][j]}(1<=i<=n;0<=j<=p)
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 typedef long long ll; 6 inline void read(int &x){ 7 x=0;char ch;bool flag = false; 8 while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true; 9 while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x; 10 } 11 inline int cat_max(const int &a,const int &b){return a>b ? a:b;} 12 inline int cat_min(const int &a,const int &b){return a<b ? a:b;} 13 const int maxn = 66; 14 double f[2][maxn][maxn]; 15 int a[maxn]; 16 int main(){ 17 int n;read(n); 18 for(int i=1;i<=n;++i) read(a[i]); 19 int p;read(p); 20 f[0][0][0] = 1.0; 21 for(int i=1;i<=n;++i){ 22 for(int j=0;j<=i;++j){ 23 for(int k=0;k<=p;++k){ 24 if(a[i] > k) f[i&1][j][k] = f[(i-1)&1][j][k]*(i-j)/i; 25 else f[i&1][j][k] = f[(i-1)&1][j][k]*(i-j)/i + f[(i-1)&1][j-1][k-a[i]]*j/i; 26 } 27 } 28 } 29 double ans = .0; 30 for(int i=1;i<=n;++i){ 31 for(int j=0;j<=p;++j){ 32 ans += f[n&1][i][j]; 33 } 34 }printf("%.10lf\n",ans); 35 getchar();getchar(); 36 return 0; 37 } 38
转载于:https://www.cnblogs.com/Skyminer/p/6257796.html
CodeForces - 261B Maxim and Restaurant相关推荐
- codeforces 261D Maxim and Increasing Subsequence(树状数组优化最长上升子列)
题目链接:http://codeforces.com/problemset/problem/261/D 题意:最长上升子列. 思路:树状数组优化求最长上升子列. #include <iostre ...
- Codeforces 854 B Maxim Buys an Apartment
题目地址 题意:告诉你一个小区,里面有n间房子,只有有邻居的房子才能是好房子,现在告诉你有m间房子卖出去了,但是不知道房子的位置.让你求出好房子的最大数量和最小数量. 思路:最好的情况只有当n - m ...
- Codeforces Round #321 (Div. 2) E
终于补好了. 题目链接: http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 sec ...
- 【Codeforces】 Round #374 (Div. 2)
Position:http://codeforces.com/contest/721 我的情况 开始还是rank1,秒出C.(11:00机房都走光了,我ma到11:05才走,只打了一个小时) 结果.. ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company 二分
B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/pr ...
- C - Social Distance CodeForces - 1367C
C - Social Distance CodeForces - 1367C 题目大意 有t组测试案例 ,输入n和k,n是桌子的数量,k是餐厅规定的每两个人之间的桌子数量,以字符串为例,n=8,k=2 ...
- L. Spicy Restaurant(多源BFS+递推)
L. Spicy Restaurant 题目链接 https://codeforces.com/gym/103117/problem/L 思路: 1.考虑到1≤ai≤100 ,一开始直接使用BFS,对 ...
最新文章
- Python 解决一行代码分成多行及多行代码放在一行
- Python常用框架:Flask
- 7.10 枚举——最大公约数和最小公倍数问题
- RxJS switchMap, mergeMap, concatMap,exhaustMap 的比较
- DOMContentLoaded与interactive
- mysql 日期和时间函数_介绍一下mysql的日期和时间函数
- ajax onerror code,Ajax请求'onError'处理程序
- HTTP的长连接和短连接通俗解释以及应用场景
- 设计模式---面向对象的设计原则概述
- 黑盒测试实践进度记录(五)
- bzoj3545/bzoj3551 [ONTAK2010]Peaks/Peaks加强版
- 《大话数据结构》读后总结(八)
- 从零开始研发GPS接收机连载——3、用HackRF软件无线电平台作为GPS模拟器
- 面向对象编程(OOP)的基本思想
- SwiftyJSON解析本地JSON文件
- 【我的Android进阶之旅】 解决Android编译出现问题:AAPT: error: resource string/xxx (aka xxx:string/xxx) not found.
- 百度网盘不限速下载方法全解(验证、体会、转载)
- linux 密码修改下次,Linux 强制使用者下次登入修改密码
- 经济学硕士读计算机博士,去美国那些大学攻读经济学博士比较好?看完你就清楚了...
- javaee笔记(10)JSF
热门文章
- ajax成功进入success但是获取不到返回值
- 【Java Web开发指南】Mybatis一对多关联映射
- 【操作系统】进程的描述与控制(这知识它不进脑子啊~!)
- 【网页前端设计Front end】CSS入门(看不懂你来打我)
- python【数据结构与算法】搜索初探
- 全卷积神经网路【U-net项目实战】LUNA 2016 数据集详解
- Tensorflow【实战Google深度学习框架】—完整的TensorFlow入门教程
- java 写流,Java IO中的其他读写流
- express 使用 redirect 对 ajax 无效 页面不跳转
- 企业网络推广中用户行为到底能为企业网络推广带来多少影响?