Kejin Player (概率DP)hdu6656
原题目:
Cuber QQ always envies those Kejin players, who pay a lot of RMB to get a higher level in the game. So he worked so hard that you are now the game designer of this game. He decided to annoy these Kejin players a little bit, and give them the lesson that RMB does not always work.
This game follows a traditional Kejin rule of "when you are level ii , you have to pay aiai RMB to get to level i+1i+1 ". Cuber QQ now changed it a little bit: "when you are level ii , you pay aiai RMB, are you get to level i+1i+1 with probability pipi ; otherwise you will turn into level xixi (xi≤ixi≤i )".
Cuber QQ still needs to know how much money expected the Kejin players needs to ``ke'' so that they can upgrade from level ll to level rr , because you worry if this is too high, these players might just quit and never return again.
Input
The first line of the input is an integer tt , denoting the number of test cases.
For each test case, there is two space-separated integers nn (1≤n≤500 0001≤n≤500 000 ) and qq (1≤q≤500 0001≤q≤500 000 ) in the first line, meaning the total number of levels and the number of queries.
Then follows nn lines, each containing integers riri , sisi , xixi , aiai (1≤ri≤si≤1091≤ri≤si≤109 , 1≤xi≤i1≤xi≤i , 0≤ai≤1090≤ai≤109 ), space separated. Note that pipi is given in the form of a fraction risirisi .
The next qq lines are qq queries. Each of these queries are two space-separated integers ll and rr (1≤l<r≤n+11≤l<r≤n+1 ).
The sum of nn and sum of qq from all tt test cases both does not exceed 106106 .
Output
For each query, output answer in the fraction form modulo 109+7109+7 , that is, if the answer is PQPQ , you should output P⋅Q−1P⋅Q−1 modulo 109+7109+7 , where Q−1Q−1 denotes the multiplicative inverse of QQ modulo 109+7109+7 .
Sample Input
1 3 2 1 1 1 2 1 2 1 3 1 3 3 4 1 4 3 4
Sample Output
22 12
中文概要:
(游戏升级)共有n+1个级别,给出前n个级别的属性,分别为r,s,x,a( r/s :成功升至第i+1级的概率,x :若升级不成功,则掉至第x级,且x比当前 i 小,a:由当前级升至第i+1级时所需要的花费)。现给出q个询问:每次求从第 L 级升至 R 级需要钱的期望。
#include <bits/stdc++.h>
using namespace std;
const int modd=1e9+7;
const int maxn=500005;
long long dp[500005];
long long qkpow(long long a,long long p,long long m)
{ long long t=1,tt=a%m; while(p) { if(p&1)t=t*tt%m; tt=tt*tt%m; p>>=1; } return t;}//快速幂求逆元long long getInv2(long long a,long long mod){ return qkpow(a,mod-2,mod);}int main()
{int t;int n,q,r,s,x,a;long long tmp;scanf("%d",&t);while(t--){scanf("%d%d",&n,&q);dp[1]=0;for(int i=1;i<=n;i++){scanf("%d%d%d%d",&r,&s,&x,&a);dp[i+1]=(dp[i]+a+modd)%modd;//防止得到负数dp[i+1]=(dp[i+1]+(r-s)%modd*getInv2(s,modd)%modd*dp[x]%modd+modd)%modd;dp[i+1]=(dp[i+1]%modd*s%modd*getInv2(r,modd)%modd)%modd;}int xx,yy; for(int i=0; i<q; i++) { scanf("%d%d",&xx,&yy); printf("%lld\n",(dp[yy]-dp[xx]+modd)%modd); } } return 0;
}
思路:
因为只能一级一级的往上升,所以存在递推关系:(队内大佬教的)
dp[i+1] = (r/s)*(dp[i] + a)+(1 - r/s)*( dp[i]+a+dp[i+1]-dp[x] )
(前者为成功需要的钱,后者为不成功所需要的钱)
=> dp[i+1] = dp[i] + a + (1 - r/s)*( dp[i+1] - dp[x] )
(dp[i]表示升至第i级所需要的金钱期望)
化简得 => dp[i+1] = (s/r)*( dp[i] + a - dp[x] ) + dp[x+1]
注意:该题给的数很大,在每次算加法时都要防止所得的数为负数,故要(+modd)%modd
递推式还好,但是那个逆元还是不太会。。。
Kejin Player (概率DP)hdu6656相关推荐
- hdu多校第七场 1011 (hdu6656) Kejin Player 概率dp
题意: 一个游戏,有许多关,到下一关要花费金钱,做出尝试,有概率成功,若成功则到达下一关,若失败则停在此关或退回到前面某关,询问第l关到第r关的期望费用 题解: 显然,第r关到第l关的费用是dp[r] ...
- HDU 6656 Kejin Player (期望DP 逆元)
2019 杭电多校 7 1011 题目链接:HDU 6656 比赛链接:2019 Multi-University Training Contest 7 Problem Description Cub ...
- 2019杭电多校第七场 HDU - 6656 Kejin Player——概率期望
题意 总共有 $n$ 层楼,在第 $i$ 层花费 $a_i$ 的代价,有 $pi$ 的概率到 $i+1$ 层,否则到 $x_i$($x_i \leq 1$) 层.接下来有 $q$ 次询问,每次询问 $ ...
- 2019HDU多校第七场 HDU6656 Kejin Player H 【期望递归】
一.题目 Kejin Player H 二.分析 因为在当前等级$i$,如果升级失败可能会退回到原来的某一等级$x$,相当于就是失败的期望就是$E + (Sum[i-1] - Sum[x-1]) + ...
- 动态规划 —— 概率 DP 与期望 DP
[概述] 由于概率和期望具有线性性质,使得可以在概率和期望之间建立一定的递推关系,这样就可以通过动态规划来解决一些概率问题,例如概率和期望的最值问题就常常使用概率 DP.期望 DP 来解决. 与其他的 ...
- 杭电多校第七场 1011 Kejin Player HDU(6656)
杭电多校第七场 1011 Kejin Player 题意:给你N行,代表从i级有花费a[i]元的r[i]/s[i]的概率达到i+1级,剩下的概率中可能会到达x[i]级.然后询问从L级到R级的花费会是多 ...
- 2019杭电多校 第七场 Kejin Player 6656(求期望值)
2019杭电多校 第七场 Kejin Player 6656(求期望值) 题目 http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意 给你n,q.表示有n ...
- 2018.09.01 poj3071Football(概率dp+二进制找规律)
传送门 概率dp简单题. 设f[i][j]表示前i轮j获胜的概率. 如果j,k能够刚好在第i轮相遇,找规律可以发现j,k满足: (j−1)>>(i−1)(j−1)>>(i−1) ...
- Discovering Gold LightOJ - 1030[概率dp或者记忆化搜索]
题目大意:有一个[1,n][1,n][1,n]的数轴,数轴上的每个对应位置上都有金矿,你初始位置是1,然后你每次都会投色子决定你下一步跳到哪里,如果你跳出了nnn,那么你就要重新投.问你跳到nnn的时 ...
- 【原创】概率DP总结 by kuangbin
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. 首先先推荐几篇参考的论文: <信息学竞赛中概率问题求解初探> & ...
最新文章
- pytorch移动端,官方helloworld不同模型仍旧好用
- python可以做什么系统-python能做哪方面的工作
- 来自51CTOHCNP3期一位技术小白的内心独白
- maven工程导入eclipse后报错
- 使用SMW0上传EXCEL模板遇到的问题
- 【Python】扫盲帖:关于在Windows、Linux和Mac上安装设置Python的问题
- XMLHttpRequest Level 2 使用指南
- 了解 Adobe Scout 收集和使用的数据
- Ubuntu16.04安装slickedit-pro2017
- 商城购物系统软件测试,网上商城购物系统黑盒测试
- leetcode1062
- 实现微信小程序上传视频的注意事项
- 金蝶BOS开发代码调用过程
- php 二维数组为空,php 判断数组是否为空的几种方法
- win10在此计算机上找不到系统映像,解决Win10系统Windows找不到文件确定是否正确...
- 计算机应用技术未来职业规划书,计算机应用技术专业大学生职业生涯规划书
- ORA-00206 ORA-00202 ORA-27061
- 库克是出色的苹果CEO 这六点可以证明
- mount error(112): Host is down
- MATLAB中对小数进行取整处理
热门文章
- 第11章 菜单及其它资源
- win10桌面快捷方式图标变白
- wordpress网站防止被别人iframe框架调用的九种方法
- 基于OpenWRT+FreeRadius+TinyRadius+Daloradius实现portal加radius安全认证
- 2W公里,就换EBC刹车片?
- java lua_请问该如何在Java中使用Lua脚本语言?
- Python Re正则表达式
- ftp - Internet 文件传输程序 (file transfer program)
- 经典 Fuzzer 工具 AFL 模糊测试指南
- 云计算介绍之云计算服务器