将整体期望分成部分期望来做。

F. network

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

题目描述

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 occurs between two nodes.

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

A simple social network,where C knows everyone but D knows just C.

Now we have already had several networks in our 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).A node is a social butterfly if and only if this node is a female and connects with at least K males.What will be the expectation of number of social butterflies in the network?

输入格式

The number of test cases T(T≤104) will occur in the first line of input.

For each test case:

The first line contains the number of nodes N(1≤N≤30)and the parameter K (0 <= K < N))

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

输出格式

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

##Hint

In the first sample, there are totally 4 cases: {Female, Female}, {Female,
Male},{Male, Female} and {Male, Male}, whose number of social butterflies
are respectively 0, 1, 1, 0. Hence, the expectation should be

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

输入样例

2
2 1
0 1
1 0
3 1
0 1 1
1 0 1
1 1 0

输出样例

0.500
1.125
//
// main.cpp
// 160323.F
//
// Created by 陈加寿 on 16/3/25.
// Copyright © 2016年 chenhuan001. All rights reserved.
// #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define N 31 int mat[N][N];
double C[N][N]; int main() {
C[][]=;
for(int i=;i<=;i++)
{
C[i][]=;
for(int j=;j<=i;j++)
{
C[i][j] = C[i-][j-]+C[i-][j];
}
} int T;
cin>>T;
while(T--)
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
for(int j=;j<n;j++)
scanf("%d",&mat[i][j]);
double ans=;
for(int i=;i<n;i++)
{
int cnt=;
for(int j=;j<n;j++)
{
cnt+=mat[i][j];
}
double tmp=;
for(int j=k;j<=cnt;j++)
tmp += C[cnt][j];
tmp = tmp/pow(2.0,cnt);
tmp *= 0.5;
ans += tmp;
}
printf("%.3lf\n",ans);
}
return ;
}
 

线性期望(BUPT2015校赛.F)的更多相关文章

  1. 校赛F

    问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...

  2. 校赛F 比比谁更快(线段树)

    http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...

  3. xdu2017校赛F

    Problem F Dogs of Qwordance Senior Backend R&D Engineers 问题描述 那年夏天,锘爷和杰师傅漫步在知春公园的小道上.他们的妻子.孩子牵 着 ...

  4. 浙江理工2015.12校赛-F Landlocked

    Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...

  5. 上海高校金马五校赛 F题:1 + 2 = 3?

    链接:https://www.nowcoder.com/acm/contest/91/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言26214 ...

  6. 广州工业大学2016校赛 F 我是好人4 dfs+容斥

    Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍 ...

  7. 北邮校赛 F. Gabriel's Pocket Money(树状数组)

    F. Gabriel's Pocket Money 2017- BUPT Collegiate Programming Contest - sync 时间限制 2000 ms 内存限制 65536 K ...

  8. 2018年东北农业大学春季校赛 F wyh的集合【思维】

    链接:https://www.nowcoder.com/acm/contest/93/F来源:牛客网 题目描述 你们wyh学长给你n个点,让你分成2个集合,然后让你将这n个点进行两两连接在一起,连接规 ...

  9. 西交校赛 F. GZP and Poker

    F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n ...

随机推荐

  1. non-compatible bean definition of same name and class

    在整合struts2.1.6+spring2.5.6开发中,使用了注解和struts-convention来实现零配置管理.spring也使用注解annotation方式.现在的问题是:我在连个个不同 ...

  2. 微信小程序 - 上传图片纯前端(多张、单张)

    演示如下 可能有些命名不太规范,到时改一下即可 点击从github拉取:图片上传示例

  3. 1364:Field 'sex' doesn't have a default value [ SQL语句 ]

    1364:Field 'sex' doesn't have a default value [ SQL语句 ]   错误解决方法: 关闭MySQL的strict mode的具体做法: 找到MySQL目 ...

  4. Linux如何根据UUID自动挂载磁盘分区

    一般服务器都有多个硬盘分区,在重启后,这些分区的逻辑位置加载时可能会发生变动,如果使用传统的设备名称(例如:/dev/sda)方式挂载磁盘,就可能因为磁盘顺序变化而造成混乱. Linux环境中每个Bl ...

  5. (一)Activiti之——简介、插件安装及BPMN元素

    1. 工作流概念 工作流(Workflow):就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程自动进行,从而实现 ...

  6. asp.net+mvc+easyui+sqlite 简单用户系统学习之旅(六)—— 简单过滤器的使用

    有些同学喜欢在测试或运行项目时,直接跳转页面到Home/Index下,但本次项目直接输入Home/Index则会报错 因为home/index中有个user.name参数,如果启动项目后直接跳转到ho ...

  7. poj 2601 Simple calculations

    Simple calculations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6559   Accepted: 32 ...

  8. libevent源码学习_event_test

    对应的sample文件中提供了event_test.c,里面就是关于事件的简单示例,具体如下: /* * Compile with: * cc -I/usr/local/include -o even ...

  9. iOS 音频开发

      音频基础知识 组成 音频文件的组成:文件格式(或者音频容器) + 数据格式(或者音频编码). 文件格式(或音频容器)是用于形容文件本身的格式. 我们可以通过多种不同的方法为真正的音频数据编码.例如 ...

  10. collection动画

    Collection View 动画 吴迪 12 May 2014 分享文章 UICollectionView 和相关类的设置非常灵活和强大.但是灵活性一旦增强,某种程度上也增加了其复杂性: UICo ...