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. php-fpm参数优化

    php-fpm参数优化 2013-11-18 Posted by yeho php-fpm进程设置多少合适,设成动态还是静态? <lnmp一键安装包>中会根据你服务器内存调整php-fpm ...

  2. [USACO2009 OPEN] 滑雪课 Ski Lessons

    洛谷P2948 看到题目就觉得这是动规但一直没想到如何状态转移……看了别人的题解之后才有一些想法 f[i][j]:前i单位时间能力值为j可以滑的最多次数 lessons[i][j]:结束时间为i,获得 ...

  3. java:集合输出之Iterator和ListIterator

    在调用Iterator集合输出时,如果想要删除某个元素,请直接使用Iterator来判断元素是否存在然后再删除(next()当前指针内容,remove()删除当前内容 );如果在将集合丢给Iterat ...

  4. 数据结构--排序--快排and冒泡(python)

    听说大厂面试,限时两分钟写出来快排... 闲着没事,写了一下... def Partition(L,low,high): pivotkey = L[low] while low<high: wh ...

  5. 微信小程序支付功能讲解

    前言:虽然小程序做过很多,但是一直觉得微信支付功能很是神秘,现在终于有机会接触心里还是有点小激动的,经过一番折腾发现支付也不过如此,在此记录下支付功能的实现过程 小程序的官方文档介绍到发起微信支付即调 ...

  6. 2017乌鲁木齐网络赛 J题 Our Journey of Dalian Ends ( 最小费用最大流 )

    题目链接 题意 : 给出一副图,大连是起点,终点是西安,要求你求出从起点到终点且经过中转点上海的最小花费是多少? 分析 : 最短路是最小费用最大流的一个特例,所以有些包含中转限制或者经过点次数有限制的 ...

  7. CopyOnWrite 个人理解以及应用

    缘由 最近在看<Redis 设计与实现>,看到Redis的执行bgsave生成dump.rdb是根据CopyOnWrite的 之前也不是很懂为啥要有CopyOnWrite这个东西 翻看文章 ...

  8. nginx之Geoip读取地域信息模块

    1 geoip_module模块 基于IP地址匹配MaxMind GeolP二进制文件,读取IP所在地域信息. yum install nginx-module-geoip geoip2已经有了,安装 ...

  9. Python用MyQR生成自定义个性二维码

    MyQR是一个能够生成自定义二维码的python第三方库,根据需要能够生成普通二维码.带背景图片的艺术二维码.动态二维码. 1.MyQR安装 安装非常简单,直接用pip install MyQR,需要 ...

  10. SSM+PageHelper 使用

    项目中使用了maven 1 引入jar包 首先需要引入PageHelper的jar包.  如果使用了maven,那么只要在pom.xml中引入该插件即可,引入如下: <dependency> ...