https://www.lydsy.com/JudgeOnline/showsource.php?id=2689580
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 typedef double db; 6 const int N=10,M=46; 7 int x,y,n,m; 8 int sz[1<<N],link[1<<N]; 9 db f[1<<N][M]; 10 int main(){ 11 scanf("%d%d",&n,&m); 12 for(register int i=0;i<m;++i){ 13 scanf("%d%d",&x,&y); 14 --x,--y; 15 link[x]|=(1<<y),link[y]|=(1<<x); 16 } 17 for(register int i=1;i<(1<<n);++i) 18 sz[i]=sz[i>>1]+(i&1); 19 for(register int S1=1;S1<(1<<n);++S1) 20 if(S1&1){ 21 for(register int S2=(S1-1)&S1;S2;S2=(S2-1)&S1) 22 if(S2&1){ 23 int T=0; 24 for(register int i=0;i<n;++i) 25 if((S1>>i)&(~S2>>i)&1) 26 T+=sz[link[i]&S2]; 27 for(register int i=0;i+T<=m;++i) 28 f[S1][i]+=1.00/(i+1+T)-f[S2][i+T]; 29 } 30 } 31 printf("%.6lf\n",f[(1<<n)-1][0]); 32 return 0; 33 }