hdu校赛 F

Problem F

Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 76    Accepted Submission(s): 25


Problem Description
A social network is a social structure made up of a set of social actors (such as individuals or organizations) and a set of the relationships between these actors. In simple cases, we may represent people as nodes in a graph, and if two people are friends, then an edge will occur between two nodes.

hdu校赛 F_第1张图片
Figure 1: C knows every one, while D only knows C in this social network.


There are many interesting properties in a social network. Recently, we are researching on the Social Butterfly in the network. A Social Butterfly should satisfy the following conditions:

1. She is a female;
2. She knows at least  K  male friends.

Now we have already taken out several networks from database, but since the data only contain nodes and edges, we don't know whether a node represents a male or a female. We are interested, that if there are equal probabilities for a node to be male and female (each with 1/2 probability), what will be the xpectation of number of social butterflies in the network?
 

Input
The number of test cases T (T <= 10^4) will occur in the first line of input.

For each test case:

The first line contains the number of nodes  N(1N30)  and the parameter  K(0K<N) .

Then an  N×N  matrix  G  followed, where  Gij=1  denotes  j  is a friend of  i , otherwise  Gij=0 . Here, it's always satisfied that  Gii=0  and  Gij=Gji  for all  1i,jN .
 

Output
For each test case, output the expectation of number of social butterflies in 3 decimals.
 

Sample Input
   
   
   
   
2 2 1 0 1 1 0 3 1 0 1 1 1 0 1 1 1 0
 

Sample Output
   
   
   
   
0.500 1.125
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf -0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
__int64 C[31][31];
int P[31];
int degree[31];

__int64 solve(int n,int m){
    if(m==0)
        return 1;
    __int64 ans=1;
    for(int i=1;i<=m;i++)
        ans=ans*(n-i+1)/i;
    return ans;
}

int main(){
    for(int i=0;i<=30;i++)
        for(int j=0;j<=i;j++)
            C[i][j]=solve(i,j);
    P[0]=1;
    P[1]=2;
    for(int i=2;i<=30;i++)
        P[i]=P[i-1]*2;
    int _,n,k,u;
    scanf("%d",&_);
    while(_--){
        scanf("%d%d",&n,&k);
        mem0(degree);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++){
                scanf("%d",&u);
                if(u==1)
                    degree[i]++,degree[j]++;
            }
        for(int i=1;i<=n;i++)
            degree[i]/=2;
        __int64 ans=0;
        for(int i=1;i<=n;i++){
            if(degree[i]>=k){
                for(int j=k;j<=degree[i];j++)
                    ans=ans+C[degree[i]][j]*P[n-degree[i]-1];
            }
        }
        printf("%.3f\n",(double)ans/(double)P[n]);
    }
    return 0;
}


你可能感兴趣的:(hdu校赛 F)