线性期望(BUPT2015校赛.F)

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

时间限制 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 31int mat[N][N];
double C[N][N];int main() {C[0][0]=1;for(int i=1;i<=30;i++){C[i][0]=1;for(int j=1;j<=i;j++){C[i][j] = C[i-1][j-1]+C[i-1][j];}}int T;cin>>T;while(T--){int n,k;scanf("%d%d",&n,&k);for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",&mat[i][j]);double ans=0;for(int i=0;i<n;i++){int cnt=0;for(int j=0;j<n;j++){cnt+=mat[i][j];}double tmp=0;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 0;
}

 

 

转载于:https://www.cnblogs.com/chenhuan001/p/5319838.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.tpcf.cn/news/255702.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【pyqt5学习】——进度条progressBar

# 进度条 self.progressBar.setValue(0) # 设置进度条的最小值 self.progressBar.setMaximum(100) # 设置进度条的最大值 # 设置进度条当前值 self.progressBar.setValue((int(curindex/excelNum)*100)) 常用方法 方法值说明setRangeQProgressBar.setRange(min, Max)通过 setR…

弧焊 不同气体对焊缝的影响 100二氧化碳 15%氩气CO2混合

Ar含量提高后&#xff0c;相比原来的100%CO2成本会提高很多。 Ar的密度比CO2小&#xff0c;焊接的焊枪必须压的很低&#xff0c;如果焊接结构中有一些狭小区域&#xff0c;焊枪则无法到达。纯CO2气体保护焊&#xff0c;焊丝可伸出较长。 Ar属于惰性气体&#xff0c;焊接时…

Windows和Linux如何使用Java代码实现关闭进程

在用selenium做自动化测试时&#xff0c;由于各种不明原因&#xff0c;有时Chrome浏览器会出现假死的情况&#xff0c;也就是整个浏览器响应超时&#xff0c;本人脚本主要部署在Windows机器上&#xff0c;所以主要以Windows为主&#xff0c;浏览器为Chrome,即如下图所示 或者由…

CSS之A标签

a标签&#xff0c;超级链接 a是英语anchor锚的意思。 a标签常用的就是三个属性&#xff1a; 1 <a href"网址" title"悬停文本" target"_blank">超级链接文字</a> 页面内的锚点&#xff0c;用name属性或者id属性 1 …

【pyqt5学习】——下拉框comboBox

# 向下拉框中添加选型&#xff0c;具体为在下拉框第index1个选型设置为内容name self.comboBox.addItem(name,index1) # 将下拉框中所有的选项删除 self.comboBox.clear() # 根据索引获取当前的下拉框内容 index self.comboBox.currentIndex() text self.comboBox.itemText(i…

安装scapy遇到的问题

1. Mac平台 在mac上安装scapy可以说是困难重重&#xff0c;一来因为scapy实在有些小众和老旧&#xff0c;再加上安装说明文档都是python2.5 也没有详细说明一些安装问题。 折腾了大概三个小时之后终于解决了这个老大难。 注&#xff1a;我的环境为anaconda2.3 - python2.7.10 一…

DAY5-小别-2018-1-15

有两天没有写了&#xff0c;前天考完试出去浪了&#xff0c;惭愧自己没有学习&#xff1b;昨天&#xff0c;启程回家看完了循环内容的视频&#xff0c;晚上十点半火车到站&#xff0c;没抽出时间写了&#xff0c;还看了《黑客帝国》&#xff0c;有点小感触&#xff0c;人工智能…

【文件处理】——Python pandas 写入数据到excel中

目录 1、创建一个新的excel表格 2、 获取写入excel的数据data 3、将data类型转换为pandas接受的类型 4、写入到excel中 5、保存excel 最终结果 #!/usr/bin/env python # -*- coding: utf-8 -*- # Time : 2021/11/9 23:18 # Author : linlianqin # Site : # File …

centerOS安装chkrootkit

Chkrootkit是一个在本地系统检查rootkit痕迹的工具&#xff0c;它是检查系统二进制文件是否被rootkit病毒修改的一个shell脚本。 &#xff08;1&#xff09;centerOS安装chkrootkit 安装gcc编译环境yum install gcc gcc-c make -y 安装chkrootkit.tar.gz 解压后执行 #make sens…

微软Visual Studio 2012软件功能介绍

对于从事.net程序开发的我们&#xff0c;都要用到C#依附的Visual Studio平台!Visual Studio是目前最流行的Windows平台应用程序开发环境。最新版本为 Visual Studio 2012 版本&#xff0c;基于 NET Framework4.5 。. Visual Studio 2012内置的测试工具可以帮助开发者打造高质量…

Spring Boot轻松理解动态注入,删除bean

2019独角兽企业重金招聘Python工程师标准>>> 我们通过getBean来获得对象,但这些对象都是事先定义好的,我们有时候要在程序中动态的加入对象.因为如果采用配置文件或者注解&#xff0c;我们要加入对象的话,还要重启服务,如果我们想要避免这一情况就得采用动态处理bea…

对象的深度克隆

最近在复习javascript&#xff0c;然而我的读书笔记&#xff0c;以及技术博客&#xff0c;已经转战cmd Markdown。所以这里就只写了一个对象的深度克隆方法&#xff1a; 这个克隆方法可以让我很深刻的了解到了js中&#xff0c;万物皆对象&#xff0c;对js有更深入的了解。转载于…

【pyqt5学习】——TextEdit属性,将滑条始终置于最后

法一&#xff1a; # 向文本框中添加字符串&#xff0c;自动换行&#xff0c;不会覆盖之前的内容 self.textEdit.append(datetime.datetime.strftime(datetime.datetime.now(),"%Y-%m-%D %H:%M:%S")" 共%d个文件&#xff0c;剩余%d个文件,耗时%.5f&#xff08;…

VS2012 中 c++项目中的各个选项介绍

MFC(Microsoft Foundation Classes)&#xff0c;是一个微软公司提供的类库&#xff08;class libraries&#xff09;&#xff0c;以C类的形式封装了Windows的API&#xff0c;并且包含一个应用程序框架&#xff0c;以减少应用程序开发人员的工作量。其中包含的类包含大量Windows…

Java基于springMVC的验证码案例

1 2 Java验证码案例&#xff08;基于springMVC方式&#xff09;3 4 验证码工具类5 package com.ekyb.common.util;6 7 import java.awt.Color;8 import java.awt.Font;9 import java.awt.Graphics;10 11 import java.awt.image.BufferedImage;12 import java.util.ArrayList;13…

eval函数的工作原理

eval函数的工作原理 eval函数会评估一个给定的含有JavaScript代码的字符串&#xff0c;并且试图去执行包含在字符串里的表达式或者一系列的合法的JavaScript语句。eval函数将把最后一个表达式或者语句所包含的值或引用作为返回值。 举例说明 eval评估JavaScript表达式var bar …

CMake使用入门

一、开胃菜 hello目录下的文件结构&#xff1a; ├── CMakeLists.txt ├── hello.c ├── hello.h └── main.c C代码见下节。 最简单的cmake配置文件&#xff1a; project(HELLO) set(SRC_LIST main.c hello.c) add_executable(hello ${SRC_LIST}) 如果要编译成gdb可调…

【pyqt5学习】——给窗口添加图标

from PyQt5.QtGui import QIcon# 当前文件的目录 self.dir os.path.dirname(os.path.abspath(__file__)) # 图标ico文件存放的绝对路径 icoPath self.dir r"\data\favicon.ico" # 添加图标 self.setWindowIcon(QIcon(icoPath))

C/C++语言变量声明内存分配

[cpp] view plaincopy<span style"font-family: Verdana, Arial, Helvetica, sans-serif; ">一个由c/C编译的程序占用的内存分为以下几个部分</span> 1、栈区&#xff08;stack&#xff09;— 程序运行时由编译器自动分配&#xff0c;存放函数的参数值…

sql server数据库实现保留指定位数小数的函数

有时候需要对一个特定的含有小数点的数字保留指定位数&#xff0c;比如“123.123600”。 在数据库中以函数的形式实现如下&#xff1a; USE [数据库名称] GO /****** Object: UserDefinedFunction [dbo].[AvgLimit] Script Date: 2016/12/29 11:30:44 ******/ SET ANSI_NUL…