概率计算- 组合 计数

九度:

http://ac.jobdu.com/problem.php?pid=1421

求总的期望值。可以单个计算每个人,最后相加。


As we all known, AbOr has a lots of girls in a palace called“Hou”(About 30 millions).

Now you are given n people without knowing their gender(Male and Female are equally likely for anyone). You also know the relationship between them! You want to know what is the expecting number of "abor" that could be found , where "abor" is defined as:

(1)Only Male might be considered;

(2)The Male who has at least m Females friends is called "abor".

输入:

The first line is one integer T indicates the number of the test cases. (T <= 10000)

Then for every case, the first line has only two integers n and m, indicating the number of people and the value of m.(0≤m≤n≤20)

Then one n by n symmetric matrix A, where A[i][j] is 1 if j is a friend of i(vice versa) and 0 otherwise;(A[i][i] is always 0)

输出:

Output the expecting number of "abor" in the given case. The answer must round to two digital after the decimal point.

样例输入:
32 101102 001103 2011101110
样例输出:
0.501.000.38

#include<cstdio>
#include<iostream>
using namespace std;
const int MaxN=25;

int N,M;
char s[MaxN][MaxN];
int C[MaxN][MaxN];
int pow2[MaxN];

int main()
{
	freopen("in.txt", "r", stdin);
    for (int i=0;i<=20;++i)
        C[i][0]=1;
    for (int i=1;i<=20;++i)
        for (int j=1;j<=i;++j)
            C[i][j]=C[i-1][j-1]+C[i-1][j];
    for (int i=pow2[0]=1;i<=20;++i)
        pow2[i]=pow2[i-1]*2;
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d",&N,&M);
        for (int i=1;i<=N;++i)
            scanf("%s",s[i]+1);
        long double ans=0;
        for (int i=1;i<=N;++i)
        {
            int p=0;
            for (int j=1;j<=N;++j)
                p+=s[i][j]-48;
            int v=0;
            for (int j=M;j<=p;++j)
                v+=C[p][j]; //v为
            ans+=(long double)v/(long double)pow2[p];
        }
        printf("%.2lf\n",(double)(ans/2));
    }
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值