Codeforces 280C Game on tree【概率DP】
Codeforces 280C Game on tree
题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数
#include<bits/stdc++.h>
using namespace std;
#define N 100010
int n,tot=0,head[N]={0};
struct Edge{int v,nxt;}E[N<<1];
void add(int u,int v){
E[++tot]=(Edge){v,head[u]};
head[u]=tot;
}
int dep[N]={0};
void dfs(int u,int fa){
dep[u]=dep[fa]+1;
for(int i=head[u];i;i=E[i].nxt){
int v=E[i].v;
if(v==fa)continue;
dfs(v,u);
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;i++){
int u,v;scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
}
dfs(1,0);
double ans=0;
for(int i=1;i<=n;i++)ans+=1.0/(double)dep[i];
printf("%lf",ans);
return 0;
}
Codeforces 280C Game on tree【概率DP】的更多相关文章
- Codeforces 461B Appleman and Tree(木dp)
题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...
- Codeforces 280C - Game on Tree
传送门:280C - Game on Tree 不知道期望是啥的请自行Baidu或Google,(溜了 题目大意,有一棵有根树,每次随机选择一个节点,将这个节点和它的子树删除,问将整棵树删除的期望次数 ...
- CodeForces 540D--Bad Luck Island(概率DP)
貌似竟然是我的第一道概率DP.. 手机码代码真不舒服.... /************************************************ Memory: 67248 KB Ti ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- CodeForces 24D Broken robot (概率DP)
D. Broken robot time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codeforces 161D Distance in Tree 树形dp
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsm ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- Codeforces 461B. Appleman and Tree[树形DP 方案数]
B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CodeForces 148D-Bag of mice(概率dp)
题意: 袋子里有w个白球b个黑球,现在两个人轮流每次取一个球(不放回),先取到白球的获胜,当后手取走一个球时,袋子里的球会随机的漏掉一个,问先手获胜的概率. 分析: dp[i][j]表示袋子中i个白球 ...
随机推荐
- 远程线程注入shellcode笔记
#include "stdafx.h" #include <windows.h> #include <stdio.h> char shellcode[] = ...
- 做文件上传下载时报这个错com.alibaba.fastjson.JSONException: illegal identifier : \
::-exec-] DEBUG c.i.e.m.I.insertDataEmebeding - <== Updates: ::-exec-] ERROR c.i.e.c.CaseArchiveC ...
- Warsaw U Contest Petrozavo dsk Summer 2011 Training Camp, Monday, September 5, 2011
Warsaw U Contest Petrozavo dsk Summer 2011 Training Camp, Monday, September 5, 2011 Problem A.Chocol ...
- C++ substr 和 substring
功能相似,但参数不同 substr(start,length); substring(start,end);
- pfSense 2.4.3 发布,包含重要的安全修复补丁
pfSense 2.4.3 已发布,本次更新包含重要的安全修复和 bug 修复,还引入了一些新特性,具体如下. 值得关注的更新 包含一些重要的安全修复补丁: Kernel PTI mitigation ...
- 设计模式--组合模式C++实现
组合模式C++实现 1定义 将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性 2类图 角色分析 Component抽象构建角色 定义参加组合独享的共同方 ...
- HttpConnection的使用
项目中需要与第三方系统交互,而交互的方式是XML报文形式,所以会用到HttpConnection与第三方系统连接交互,使用起来并不复杂,但是有几点需要注意的: 1.乱码的问题解决 2.超时的设置,注意 ...
- oom_killer
Limited Memory 今天在虚拟机里面用Word处理文档的时候,突然硬盘灯一阵狂闪,然后虚拟机就一起消失了. 这种事情屡见不鲜,很明显是Linux内核把占用最多内存的程序(这次是Virtual ...
- MyCat入门指南
入门篇 1. 安装 1.1从https://github.com/MyCATApache/Mycat-download下载压缩包 1.2解压缩后复制到相应目录下面,比如/usr/local ...
- CF911A
题解: 先按照a大小排序(要双关键字) 然后和a[1]一样的按照b减一减,取最小 代码: #include<bits/stdc++.h> using namespace std; ; in ...