線性期望(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(T104)?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 (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?1i,jN.

輸出格式

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.pswp.cn/news/255702.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/255702.shtml
英文地址,請注明出處:http://en.pswp.cn/news/255702.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋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…