51nod1632 B君的连通

链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1632

题意:中文题。

分析:原本是一棵树,求删一些边后联通块的期望。很明显联通块个数只和删的边数量有关,即C(n-1,m)*(m+1),n-1条边删m条边得m+1个联通块。

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const ll MAX=1ll<<55;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
ll inv[N];
int main()
{
    int i,n,x,y;
    ll now=1,ans=1;
    scanf("%d", &n);
    inv[1]=1;
    for (i=2;i<=n+1;i++) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
    for (i=1;i


你可能感兴趣的:(online,数学,期望)