您的位置:首页 > 其它

线性期望(BUPT2015校赛.F)

2016-03-25 16:00 330 查看
将整体期望分成部分期望来做。

F.network

时间限制3000ms内存限制65536KB

题目描述

Asocialnetworkisasocialstructuremadeupofasetofsocialactors(suchasindividualsororganizations)andasetoftherelationshipsbetweentheseactors.Insimplecases,wemayrepresentpeopleasnodesinagraph,andiftwopeoplearefriends,thenanedgeoccursbetweentwonodes.

Therearemanyinterestingpropertiesinasocialnetwork.Recently,weareresearchingontheSocialButterfly.Asocialbutterflyshouldsatisfythefollowingconditions:


Asimplesocialnetwork,whereCknowseveryonebutDknowsjustC.

Nowwehavealreadyhadseveralnetworksinourdatabase,butsincethedataonlycontainnodesandedges,wedon'tknowwhetheranoderepresentsamaleorafemale.Weareinterested,thatifthereareequalprobabilitiesforanodetobemaleandfemale(eachwith1/2probability).AnodeisasocialbutterflyifandonlyifthisnodeisafemaleandconnectswithatleastKmales.Whatwillbetheexpectationofnumberofsocialbutterfliesinthenetwork?

输入格式

ThenumberoftestcasesT(T≤104)willoccurinthefirstlineofinput.

Foreachtestcase:

ThefirstlinecontainsthenumberofnodesN(1≤N≤30)andtheparameterK(0<=K<N))

ThenanN×NmatrixGfollowed,whereGij=1denotesjasafriendofi,otherwiseGij=0.Here,it'salwayssatisfiedthatGii=0andGij=Gjiforall1≤i,j≤N.

输出格式

Foreachtestcase,outputtheexpectationofnumberofsocialbutterfliesin3decimals.

##Hint

Inthefirstsample,therearetotally4cases:{Female,Female},{Female,
Male},{Male,Female}and{Male,Male},whosenumberofsocialbutterflies
arerespectively0,1,1,0.Hence,theexpectationshouldbe

E=14×0+14×1+14×1+14×0=12

输入样例

2
21
01
10
31
011
101
110


输出样例

0.500
1.125


//
//main.cpp
//160323.F
//
//Createdby陈加寿on16/3/25.
//Copyright©2016年chenhuan001.Allrightsreserved.
//

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
usingnamespacestd;
#defineN31

intmat

;
doubleC

;

intmain(){
C[0][0]=1;
for(inti=1;i<=30;i++)
{
C[i][0]=1;
for(intj=1;j<=i;j++)
{
C[i][j]=C[i-1][j-1]+C[i-1][j];
}
}

intT;
cin>>T;
while(T--)
{
intn,k;
scanf("%d%d",&n,&k);
for(inti=0;i<n;i++)
for(intj=0;j<n;j++)
scanf("%d",&mat[i][j]);
doubleans=0;
for(inti=0;i<n;i++)
{
intcnt=0;
for(intj=0;j<n;j++)
{
cnt+=mat[i][j];
}
doubletmp=0;
for(intj=k;j<=cnt;j++)
tmp+=C[cnt][j];
tmp=tmp/pow(2.0,cnt);
tmp*=0.5;
ans+=tmp;
}
printf("%.3lf\n",ans);
}
return0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: