bzoj 5091: 摘苹果
来源:互联网 发布:网络运营公司赚钱吗 编辑:程序博客网 时间:2024/06/07 02:41
题意:
小Q的工作是采摘花园里的苹果。在花园中有n棵苹果树以及m条双向道路,苹果树编号依次为1到n,每条道路的两
端连接着两棵不同的苹果树。假设第i棵苹果树连接着
1.小Q随机移动到一棵苹果树下,移动到第i棵苹果树下的概率为
2.等概率随机选择一条与当前苹果树相连的一条道路,移动到另一棵苹果树下。
3.假设当前位于第i棵苹果树下,他会采摘
4.重复第2和3步k次。
计算小Q期望摘到多少苹果。
题解:
如果想要通过一般的期望dp做,反正我不会。
所以换一个思路,计算在第i次到每棵树的概率。
先考虑第二次:
发现不变。
于是就很简单了。
code:
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#define LL long longusing namespace std;const LL mod=1000000007;LL n,m,k;LL a[100010],d[100010];LL pow(LL a,LL b){ LL ans=1; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod;b>>=1; } return ans;}LL ans=0;int main(){ scanf("%lld %lld %lld",&n,&m,&k); for(LL i=1;i<=n;i++) scanf("%lld",&a[i]); for(LL i=1;i<=m;i++) { LL x,y;scanf("%lld %lld",&x,&y); d[x]++;d[y]++; } for(LL i=1;i<=n;i++) ans=(ans+a[i]*d[i]%mod)%mod; ans=ans*k%mod; //printf("%lld %lld\n",ans,2*m); printf("%lld",ans*pow(2*m,mod-2)%mod);}
阅读全文
1 0
- bzoj 5091: 摘苹果
- bzoj 5091: 摘苹果 期望+乱搞
- BZOJ 2645 陶陶吃苹果 [树形DP]
- XJOI2080 BZOJ 3640 JC的小苹果
- 摘苹果
- [概率 高斯消元 逆矩阵] BZOJ 3640 JC的小苹果
- bzoj 2645: Vijos1676 陶陶吃苹果 (树形DP)
- bzoj 5241. 【GDOI2018模拟8.8】苹果和雪梨 贪心
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果/BZOJ 1750: [Usaco2005 qua]Apple Catching dp
- 1144. 陶陶摘苹果
- sjtu1001.二哥摘苹果
- 【模拟】陶陶摘苹果
- 1144. 陶陶摘苹果
- 陶陶摘苹果
- 二哥摘苹果问题
- 陶陶摘苹果
- vijos1102淘淘摘苹果
- 陶陶摘苹果
- LeetCode-88. Merge Sorted Array
- Hbase初始化并根据RowKey获取数据
- 3-1 Point类的构造函数
- 292. Nim Game
- cookie存储及取出时间问题
- bzoj 5091: 摘苹果
- 嵌入式六部曲
- python 第三课
- 设置Hbase的环境变量
- error:src refspec master does not match any
- 网络Cisco实验-交换机路由器综合实验(静态路由)
- ListView 更改表头字体颜色
- [leetcode] 21. Merge Two Sorted Lists
- PC重装机