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

最新文章

  1. linux NFS 配置步骤
  2. 一种Go使用tcp检测超时的方式
  3. TCP/IP详解 学习七
  4. 湖大 11404 manacher
  5. POJ 1860 Currency Exchange (bellman-ford判负环)
  6. bzoj1233
  7. hdu 5605 geometry(几何,数学)
  8. JQuery - 去除所有空格
  9. SilkTest Q&amp;A 6
  10. IE6-7下margin-bottom不兼容解决方法(非原创,视频中看到的)
  11. 2017-5-18 Repeater 重复器的使用
  12. css预处理器之一---sass(一)
  13. 单元测试系列:Mock工具之Mockito实战
  14. C# 使用lambda表达式过滤掉数组中的空字符串
  15. python IO 多路复用
  16. 模板, 保存&amp;发布
  17. 利用Xml架构生成实体访问类
  18. Wannafly挑战赛27-A/B
  19. CryptoZombies学习笔记——Lesson2
  20. c++中的前置声明

热门文章

  1. Spring Boot 整合Spring Data JPA
  2. 【leetcode】845. Longest Mountain in Array
  3. IDEA unable to find valid certification path to requested target
  4. Delphi 2010 secondsBetween Bug
  5. centos搭建lamp环境参考(根据腾讯云实验室)
  6. 【bzoj1179】[Apio2009]Atm
  7. 每隔2分钟,div元素顺序淡入
  8. [LOJ2288][THUWC2017]大葱的神力:搜索+背包DP+费用流+随机化
  9. telnet测试端口是否打开?
  10. redux源码浅入浅出