日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【2019icpc徐州站】Random Access Iterator(概率dp,有坑,tricks)

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【2019icpc徐州站】Random Access Iterator(概率dp,有坑,tricks) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Recently Kumiko learns to use containers in C++ standard template library.

She likes to use the?std::vector?very much. It is very convenient for her to do operations like an ordinary array. However, she is concerned about the random-access iterator use in the?std::vector. She misunderstanding its meaning as that a vector will return an element with equal probability in this container when she access some element in it.

As a result, she failed to solve the following problem. Can you help her?

You are given a tree consisting of?nn?vertices, and?11?is the root of this tree. You are asked to calculate the height of it.

The height of a tree is defined as the maximum number of vertices on a path from the root to a leaf.

Kumiko's code is like the following pseudo code.

She calls this function?dfs(1, 1), and outputs the maximum value of depth array.

Obviously, her answer is not necessarily correct. Now, she hopes you analyze the result of her code.

Specifically, you need to tell Kumiko the probability that her code outputs the correct result.

To avoid precision problem, you need to output the answer modulo?10^9 + 7109+7.

Input

The first line contains an integer?nn?- the number of vertices in the tree?(2 \le n \le 10^6)(2≤n≤106).

Each of the next?n - 1n?1?lines describes an edge of the tree. Edge?ii?is denoted by two integers?u_iui??and?v_ivi?, the indices of vertices it connects?(1 \le u_i, v_i \le n, u_i \cancel= v_i)(1≤ui?,vi?≤n,ui?=?vi?).

It is guaranteed that the given edges form a tree.

Output

Print one integer denotes the answer.

樣例輸入復制

5 1 2 1 3 3 4 3 5

樣例輸出復制

750000006

樣例解釋

Kumiko's code has?\frac{3}{4}43??probability to output the correct answer.

題目大意:

給定一棵樹,1號節點為根節點,定義了一下一棵樹的深度。定義一個過程:從根節點出發,在節點x有son[x]次重復操作(son[x]為x節點的兒子節點個數),每次操作等概率進入某一兒子節點,同時記錄最深深度dep。

現在調用一次dfs(1),求? ?dep==樹的深度? 的概率。

解題報告:

就是個n次獨立重復試驗,每一次的概率算出來,求個son[x]次方就行了。

注意判斷葉子結點的時候別忘了特判根節點。、。。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 1e6 + 5; const ll mod = 1e9 + 7; ll qpow(ll a,ll b) {ll res = 1;while(b) {if(b&1) res = (res * a) % mod;b>>=1;a = (a*a)%mod;}return res; } int n,dep[MAX],ansd; ll dp[MAX]; vector<int> vv[MAX]; void dfs(int cur,int fa,int deep) {dep[cur] = deep;ansd = max(ansd,deep);int up = vv[cur].size();for(int i = 0; i<up; i++) {int v = vv[cur][i];if(v == fa) continue;dfs(v,cur,deep+1);} } void f(int cur,int fa) {if(vv[cur].size() == 1 && cur != 1) {if(dep[cur] == ansd) dp[cur] = 1;else dp[cur] = 0;return;}int up = vv[cur].size(),upp = vv[cur].size() - (cur!=1);ll tmp = 0; for(int i = 0; i<up; i++) {int v = vv[cur][i];if(v == fa) continue;f(v,cur);tmp += dp[v] *(qpow(upp,mod-2))%mod;tmp%=mod;}tmp = mod + 1 - tmp;//一次錯誤的tmp%=mod;tmp = qpow(tmp,upp)%mod; dp[cur] = mod+1-tmp;dp[cur]%=mod; } int main() {cin>>n;if(n == 1) {printf("1\n");return 0;}for(int u,v,i = 1; i<=n-1; i++) {scanf("%d%d",&u,&v);vv[v].pb(u);vv[u].pb(v);}dfs(1,0,1);f(1,0);printf("%lld\n",dp[1]);return 0 ; }

?

總結

以上是生活随笔為你收集整理的【2019icpc徐州站】Random Access Iterator(概率dp,有坑,tricks)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 成人网站免费观看 | 国产激情影院 | 免费看国产片在线观看 | 九九在线观看视频 | 哪里有毛片看 | 原创露脸88av | 成人片网址 | 午夜剧场免费观看 | 五月丁香久久婷婷 | 最近2018年手机中文字幕版 | 亚洲一区视频 | 欧美韩一区| 一区二区三区高清在线观看 | 涩涩视频在线 | 美女被草出白浆 | 免费在线观看av网站 | 国产美女又黄又爽又色视频免费 | 蜜桃视频黄色 | 青青视频网站 | 一区二区在线观看视频 | 九九视频免费 | 在线播放免费av | 在线观看成年人视频 | 国产精品17p | 91色视频在线观看 | 男人天堂新地址 | 久久精彩视频 | 污漫在线观看 | 午夜中文字幕 | 致单身男女免费观看完整版 | 农村妇女精品一区二区 | 中文字幕欧美视频 | 四虎影成人精品a片 | 懂色av一区二区三区蜜臀 | 国产一级片自拍 | 国产91大片 | 精品久久久久久久久久久久久久 | 美女张开双腿让男人捅 | 日本一区成人 | 免费在线观看国产精品 | 亚洲五月花 | 久久亚洲av成人无码国产电影 | 欧美日韩一区精品 | 91免费黄视频 | 国产亚洲色婷婷久久 | 97国产精品视频人人做人人爱 | 国产午夜福利视频在线观看 | 精品一区二区三区四区五区 | jizz国产 | 人妻少妇偷人精品无码 | 高hnp视频 | 欧美日本一道本 | xxxx.国产| 一区二区三区日韩 | www青青草 | 国产成人精品白浆久久69 | 久久精品性 | 黄色你懂的 | 欧美视频精品 | 久草黄色 | 国产视频精品免费 | www.久久精品| 国产一区二区三区四区视频 | 男女作爱网站 | 美女狂揉羞羞的视频 | 免费观看的av | 隔壁人妻偷人bd中字 | 手机福利视频 | 侵犯女教师一区二区三区 | 久久久亚洲成人 | 少妇裸体性生交 | 日本在线h | 中文字幕一区二区三区久久久 | 四虎黄色网址 | 国产三级在线观看 | 亚洲二区在线观看 | 国产一级理论 | 无码人妻精品一区二 | 夜间福利在线 | 欧美一级录像 | h视频在线看 | 女女同性女同一区二区三区按摩 | 美女视频黄色免费 | 国产美女永久无遮挡 | 国产 日韩 欧美 在线 | 波多野吉衣一二三区乱码 | 欧美精选一区二区 | www.亚洲国产 | 999成人网| 国产精品久免费的黄网站 | 成人拍拍拍 | 亚洲一区二区精品视频 | 久久亚洲精品视频 | 午夜影视免费 | 成人第一页 | 国产一区999 | 免费在线观看污 | 91麻豆蜜桃 | 伊人黄|