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

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. vue - 总结build.js

    1. 导入外部包,用关键字 const :ES2015->不可变量 内部使用变量,let -> 块级声明 2.无分号结尾(我猜大概是用了es6变量,避免了es5应缺少分号出现的一些问题) ...

  2. javaSE中的输入输出流---一个读取流,相应多个输出流。并且生成的碎片文件都有有序的编号

    <span style="font-size:18px;">package com.io.other.split; import java.io.File; impor ...

  3. 悟道—位IT高管20年的职场心经(读书笔记三)

    悟道--一位IT高管20年的职场心经 第三章 世事洞明皆学问 职场就是你的大半个世界 是你一辈子也读不完的一大本书 想明确一个道理. 看明确一件事儿, 你就向成功迈进了一步. 1.1  "四 ...

  4. 使用Nginx+uWSGI+Django方法部署Django程序(下)

    在上一篇文章<五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)>中,阐述了如何只使用uWSGI来部署Django程序. 当然,单单只有uWSGI是不够的, ...

  5. 首先给大家介绍一下数据库project师,数据库project师(Database Engineer),是从事管理和维护数据库管理系统(DBMS)

    摘要 MySQL的最初的核心思想,主要是开源.简便易用.其开发可追溯至1985年,而第一个内部发行版本号诞生,已经是1995年. 到1998年,MySQL已经能够支持10中操作系统了.当中就包含win ...

  6. Qt Creator项目中使用qss

    近期学习qt .使用的编译器是qt creator ,学习过程中遇到的题就是 怎样将程序中将要用到的.qss 文件静态编译到.exe程序中,而不是在程序执行时动态加载.动态加载的最大问题在于一旦.qs ...

  7. SSH——基于BaseDao和BaseAction实现用户登录

           基于BaseDao和BaseAction实现用户登录  1. 首先修改login.jsp页面,点击登录按钮,提交表单 <a onclick="document.forms ...

  8. StandardServer.await: create[8005]java.net.BindException: Address already in use: JVM_Bind错误

    StandardServer.await: create[8005]java.net.BindException: Address already in use: JVM_Bind错误. 原因是:To ...

  9. smartconfig配置模式

    http://www.tuicool.com/articles/E3a2myi 这项技术由德州仪器提出, 并且应用在自己的CC3000系列芯片上. 不过, 从原理上来说, 支持混杂模式的wifi芯片都 ...

  10. emcas自己所熟悉的快捷键

    刚开始用emacs,看完Tutorial了后又用emcas做了一些笔记. 现将自己脑海中觉得比较重要的快捷键一一列出,该列表将持续更新: C = Ctrl  M = Alt 查找或打开(新)文件 C- ...