Problem Statement
    
Charlie has N pancakes. He wants to serve some of them for breakfast. We will number the pancakes 0 through N-1. For each i, pancake i has width i+1 and deliciousness d[i].
Charlie chooses the pancakes he is going to serve using the following randomized process: He starts by choosing the first pancake uniformly at random from all the pancakes he has. He places the chosen pancake onto a plate. This pancake now forms the bottom of a future stack of pancakes. Then, Charlie repeats the following procedure:
If there are no more pancakes remaining, terminate.
Choose a pancake uniformly at random from the pancakes that have not been chosen yet.
If the width of this pancake is greater than the width of the pancake on top of the stack, terminate without taking it.
Place the chosen pancake on top of the stack and go back to step 1.
You are given the vector <int> d with N elements. The total deliciousness of a serving of pancakes is the sum of the deliciousness of all pancakes used in the serving. Compute and return the expected value of the total deliciousness of the pancakes chosen by Charlie.
Definition
    
Class:
RandomPancakeStack
Method:
expectedDeliciousness
Parameters:
vector <int>
Returns:
double
Method signature:
double expectedDeliciousness(vector <int> d)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB):
256
Stack limit (MB):
256
Notes
-
Your return value must have an absolute or relative error smaller than or equal to 1e-6
Constraints
-
The number of elements in d will be between 1 and 250, inclusive.
-
Each element of d will be between 1 and 1,000, inclusive.
Examples
0)

{1,1,1}
Returns: 1.6666666666666667
The following scenarios may occur:
With probability 1/3, Charlie chooses pancake 0 first. In this case he won't be able to add any more pancakes and the total deliciousness of his serving of pancakes will be 1.
With probability 1/3, Charlie chooses pancake 1 first. What happens in the second round? With probability 1/2 he will choose pancake 0 and with probability 1/2 it will be pancake 2. In the first case the total deliciousness of Charlie's pancakes will be 2, in the second case it will be 1.
With probability 1/3, Charlie chooses pancake 2 first. If he chooses pancake 0 next, the total deliciousness of his pancakes will be 2. If he happens to choose pancake 1 next (followed by pancake 0 in the third round), the total deliciousness will be 3.
Summing this up, we get the expected deliciousness to be 1/3 * (1) + 1/3 * (1/2 * 1 + 1/2 * 2) + 1/3 * (1/2 * 2 + 1/2 * 3) = 5/3 = 1.666...
1)

{3,6,10,9,2}
Returns: 9.891666666666667

2)

{10,9,8,7,6,5,4,3,2,1}
Returns: 10.999999724426809

3)

{1,2,3,4,5,6,7,8,9,10}
Returns: 7.901100088183421

4)

{2,7,1,8,2,8,1,8,2,8,4,5,90,4,5,2,3,5,60,2,8,74,7,1}
Returns: 19.368705050402465

5)

{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 1.718281828459045

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

期望Dp, 不得不承认自己是个概率白痴,这么简单的问题都想了这么久

dp[i][j] 表示选到第i个 ,选了j 个还能选多少个的期望~

#include <bits/stdc++.h>
using namespace std;
const int N = ;
class RandomPancakeStack
{
public:
double dp[N][N] , dd[N];
bool vis[N][N];
int n ; double Dp( int i , int cnt ) {
if( i == ) return dd[] ;
if( !vis[i][cnt] ) {
vis[i][cnt] = true ;
double &c = dp[i][cnt] ;
c = dd[] ;
for( int j = ; j <= i ; ++j ) {
c += 1.0 * ( n - j - cnt ) / ( n - cnt - 1.0 ) * dd[j] + ( 1.0 - 1.0 * ( n - j - cnt ) / ( n - cnt - 1.0 ) ) * ( dd[j] + Dp( j - , cnt + ) ) ;
}
c *= 1.0 / i ;
}
return dp[i][cnt] ;
} double expectedDeliciousness( vector <int> d ){
n = (int) d.size() ;
for( int i = ; i < n ; ++i ) dd[i+] = ( double )d[i] ;
memset( vis , false , sizeof vis );
return Dp( n , );
}
};

Topcoder SRM656div1 250 ( 期望DP )的更多相关文章

  1. P3239 [HNOI2015]亚瑟王 期望 dp

    LINK:亚瑟王 Saber!Excalibur! 比较难的期望dp. 可以发现如果暴力枚举所有的局面复杂度很高 . 转换的思路则是 期望的线性性. 求出每张牌的期望累加即可. 考虑每张牌的期望=这张 ...

  2. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

  3. [NOIP2016]换教室 D1 T3 Floyed+期望DP

    [NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...

  4. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  5. 【BZOJ-4008】亚瑟王 概率与期望 + DP

    4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec  Memory Limit: 512 MBSec  Special JudgeSubmit: 832  Solved: 5 ...

  6. 期望dp BZOJ3450+BZOJ4318

    BZOJ3450 概率期望DP f[i]表示到i的期望得分,g[i]表示到i的期望长度. 分三种情况转移: ① s[i]=‘x’:f[i]=f[i-1],g[i]=0 ② s[i]=‘o’:f[i]= ...

  7. HDU 4405 期望DP

    期望DP算是第一题吧...虽然巨水但把思路理理清楚总是好的.. 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落到a点时直接飞向b点.求走到n ...

  8. POJ 2096 【期望DP】

    题意: 有n种选择,每种选择对应m种状态.每种选择发生的概率相等,每种选择中对应的每种状态发生的概率相等. 求n种选择和m种状态中每种至少发生一次的期望. 期望DP好别扭啊.要用倒推的方法. dp[i ...

  9. ZOJ 3822 Domination 期望dp

    Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...

随机推荐

  1. selenium定位

    https://www.cnblogs.com/programer-xinmu78/p/10881766.html https://www.cnblogs.com/eastonliu/p/908830 ...

  2. 使用VisualStudio 开发Arduino

    Arduino IDE界面简洁,整体功能还算完善,相比其他编译器明显的不足就是不能进行硬件调试,再就是没有代码提示功能,文件关系不清晰.头文件打开不方便. VisualStudio作为时下最为流行的W ...

  3. logstash+redis收集负载均衡模式下多台服务器的多个web日志

    一.logstash的简介 一般我们看日志来解决问题的时候要么 tail+grep 要么 把日志下载下来再搜索,可以应付不多的主机和应用不多的部署场景.但对于多机多应用部署就不合适了.这里的多机多应用 ...

  4. HTTP教程

    适合人群 本教程已为计算机学科毕业生和Web开发人员准备,帮助他们了解与超文本传输​​协议(HTTP)相关的基本到高级概念. 预备知识 在继续本教程之前,最好对Web概念,Web浏览器,Web服务器, ...

  5. 弹性盒子FlexBox简介(二)

    弹性盒子属性 一.align-content属性 属性作用:用于修改flex-wrap属性行为.类似于justify-content,但它不是设置弹性子元素的对齐,而是设置各个行的对齐. 属性值: f ...

  6. RN组件的生命周期

    来自:http://www.devio.org/tags/#React%20Native

  7. getCurrentPages

    解释:getCurrentPages 全局函数用于获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面. 示例: // index.jsPage({ onShow( ...

  8. java 如何实现大文件上传下载(传输)各种格式

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...

  9. R 配色(挑花眼的色卡19色)

    cols =c("#999999","#FF0099", "#E69F00", "#56B4E9", "#00 ...

  10. 使用visual studio配置和运行《opengl圣经》的第一个案例

    对vc++新手来说,想把opengl圣经里的教学案例运行起来还真不是一件容易的事情,而且并没有完整的操作流程教学,这里就总结一下吧: 先安装cmake,用于生成vs的工程文件,安装过程中选中“将目录添 ...