Poj3557 (probability dp)
Given n, p; indicates that the probability of any two points in n points is p, and the graph generated is the probability of a connected block. N <= 20
Solution: reverse thinking. When ans [I] is the probability that I nodes are connected blocks, calculate the probability of not a connected block when ans [n], and then subtract 1. For non-connectivity, You can enumerate the number of points that are connected to node 1.
Formula: ans [I] = 1.0-sigma C [I-1] [J-1] * ans [j] * pow (1.0-p, j * (I-j )) --- j from 1 to I-1;
Code:
/******************************************************* @author:xiefubao*******************************************************/#pragma comment(linker, "/STACK:102400000,102400000")#include
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
#include
//freopen ("in.txt" , "r" , stdin);using namespace std;#define eps 1e-8#define zero(_) (abs(_)<=eps)const double pi=acos(-1.0);typedef long long LL;const int Max=22;const LL INF=0x3FFFFFFF;double ans[23];int n;double p;LL C[30][30];void init(){ for(int i=0; i