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个白球 ...
随机推荐
- Glibc-2.3.4编译
$tar xf Glibc2.3.4.tar.bz2 $mkdir build_glibc $cd build_glibc ../glibc-2.3.4/configure --prefix=/too ...
- TensorFlow备忘录——conv2d函数
卷积函数 TensorFlow学习备忘录 tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_forma ...
- 安装 inotify-tools
摘要 inotify-tools, 是一款google出的用于监控文件系统的软件. 一.软件下载地址官方站点地址:http://inotify-tools.sourceforge.net/仓库地址:h ...
- Flutter新手第一个坑:Could not find com.android.tools.lint:lint-gradle:26.1.1.
解决方法1:修改build.gradle,注释掉jcenter(),google().使用阿里的镜像.原因是jcenter google库无法访问到导致的问题.虽然我有万能的爬墙工具,开启全局代理依然 ...
- MySQL5.7 半同步复制
一.概述 5.5与5.7的半同步复制可能存在差异,从MySQL5.5开始,MySQL以插件的形式支持半同步复制 异步:默认情况下,MySQL复制是异步的.主库在执行完客户端提交的事务后会立即将结果返给 ...
- 初识HTML和CSS2
上节作业问题: 1.css重用 <style> 如果整个页面的宽度 > 900px时: { .c{ 共有 } .c1{ 独有 } } .c2{ 独有 } </style> ...
- PowerDesigner中NAME和COMMENT的互相转换
原文: http://www.cnblogs.com/yelaiju/archive/2013/04/26/3044828.html 由于PDM 的表中 Name 会默认=Code 所以很不方便, 所 ...
- Android6.0------权限申请管理(单个权限和多个权限申请)
Android开发时,到6.0系统上之后,有的权限就得申请才能用了. Android将权限分为正常权限 和 危险权限 Android系统权限分为几个保护级别.需要了解的两个最重要保护级别是 正常权限 ...
- mysql too many connections解决方法
MySQL提示“too many connections”的解决办法 今天生产服务器上的MySQL出现了一个不算太陌生的错误“Too many connections”.平常碰到这个问题,我基本上 ...
- python类常用装饰器
class Myclass(object): def __init__(self): pass #必须实例化才能调用 def sayhi(self): print 'hello' #静态方法,跟类没什 ...