• luogu3830 [SHOI2012]随机树


    ref
    主要学到了期望有时候直接当平均值就好了,还有就是一个期望的问题:

    (E(x)=sum_{i=1}^infty P(x geq i)),他的意思是说对于一个变量 (x),他的期望值是 (x geq i) 的概率之和。为什么呢?

    (E(x)=0(P(geq 0)-P(geq 1)) + 1(P(geq 1)-P(geq 2))+cdots)

    这样比较像差分,就很容易证明了。

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int q, n;
    namespace touhou{
    	double f[105];
    	void main(){
    		for(int i=2; i<=n; i++)
    			f[i] = f[i-1] + 2.0 / i;
    		printf("%.6f
    ", f[n]);
    	}
    }
    namespace project{
    	double f[105][105], ans;
    	void main(){
    		for(int x=1; x<=n; x++){
    			f[x][0] = 1;
    			for(int d=1; d<=x; d++){
    				for(int i=1; i<x; i++)
    					f[x][d] += f[i][d-1] + f[x-i][d-1] - f[i][d-1] * f[x-i][d-1];
    				if(x!=1)	f[x][d] /= x - 1;
    			}
    		}
    		for(int i=1; i<=n; i++)
    			ans += f[n][i];
    		printf("%.6f
    ", ans);
    	}
    }
    int main(){
    	cin>>q>>n;
    	if(q&1)	touhou::main();
    	else	project::main();
    	return 0;
    }
    
  • 相关阅读:
    groovy集合
    groovy函数、字符串、循环
    groovy运行程序和类型推断
    常见IT英语短语一
    常见IT英语单词
    认识Groovy
    maven入门
    springboot之内嵌tomcat修改端口号
    springboot手动配置数据源:
    img与父元素的间隙解决
  • 原文地址:https://www.cnblogs.com/poorpool/p/9103497.html
Copyright © 2020-2023  润新知