poj 3557 Map Generator 概率
来源:互联网 发布:查询电脑8000端口号 编辑:程序博客网 时间:2024/05/16 09:15
巧妙的是枚举的方法,对于新的一个点i,我们知道整个图是不连通的,那么i所在的连通图一定与某个点不连通,所以枚举i所在的连通图的大小
#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#include <bitset>#include <cmath> using namespace std; #define print(x) cout<<x<<endl#define input(x) cin>>x#define SIZE 25 double dp[SIZE];int n;double p;int C[SIZE][SIZE]; void init(){ for(int i=0;i<SIZE;i++) { C[i][0]=C[i][i]=1; } for(int i=2;i<SIZE;i++) { for(int j=1;j<i;j++) { C[i][j]=C[i-1][j]+C[i-1][j-1]; } }} int main(){ input(n>>p); init(); dp[1]=1.; for(int i=2;i<=n;i++) { double ans=0; /* dp[i]为在当前情况下,构成i个点的连通点集的概率 * * 若要计算dp[i],则要从i-1的点中,划分出一个j-1的子集,所以共有C(i-1,j-1)的子集 * 然后再将这个j-1子集,加上新加入的点,若使这j个点构成连通点集,概率为dp[j] * 若使这i个点不连通,则在上面所说的两个字集之间没有连通的边,一共有j*(i-j)种可能的边 * 所以概率为(1-p)^(j*(i-j)) * * 将j=(1,i-1)的所有情况加到一起,得到的就是有i个点的情况下,不能构成连通图的概率 * 所以dp[i]=1-sigma(C[i-1][j-1]*dp[j]*pow(1-p,double(j*(i-j))) * */ for(int j=1;j<i;j++) { ans+=C[i-1][j-1]*dp[j]*pow(1-p,double(j*(i-j))); } dp[i]=1-ans; } print(dp[n]); return 0;}
0 0
- poj 3557 Map Generator 概率
- 【POJ 3557】Map Generator
- poj3557 Map Generator(概率dp)及其扩展
- 概率统计--MAP
- POJ 1597 Uniform Generator
- poj 1597 Uniform Generator
- poj 1597 Uniform Generator
- 【概率dp】POJ 2151
- 【概率dp】POJ 3071
- poj 2096 概率dp
- poj 2096 概率dp
- POJ 1322 概率DP
- poj-2151-概率dp
- poj 3071 概率dp
- poj 2151(概率dp)
- 概率 DP POJ 2151
- poj 1322 概率DP
- poj 2151 概率DP
- eclipse调试openstack的nova代码
- org/apache/struts2/util/ObjectFactoryDestroyable错误
- <7.21>新的启航 Android学习笔记(一)
- 学习Swift笔记 (十)Swift的类和结构
- crm操作传真实体
- poj 3557 Map Generator 概率
- 12100-Printer Queue【STL模拟】
- bestcoder round #1
- 移动+免费,网络文学新起点
- Ubuntu下搭建FTP服务器
- 查找List 某一段数据
- C#后台获取前台JS写的Cookie
- HDU 1069 Monkey and Banana (动规)
- struts返回值类型