【HDU】6410:序列期望
序列期望
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 247 Accepted Submission(s): 119
Problem Description
“看似随机,实则早已注定”——光羽
度度熊有n个随机变量x1,x2,...,xnx1,x2,...,xn。给定区间[l1,r1],...,[ln,rn][l1,r1],...,[ln,rn],变量xixi的值会等概率成为区间[li,ri][li,ri]中的任意一个整数。
显然这n个随机变量的值会有一共∏ni=1(ri−li+1)∏i=1n(ri−li+1) 种情况,且每种情况出现的概率为∏ni=11ri−li+1∏i=1n1ri−li+1
对于某种情况,令h=maxx1,x2,...,xnh=maxx1,x2,...,xn,定义这种情况的权值为:∏ni=1(h−xi+1)∏i=1n(h−xi+1).
度度熊想知道权值的期望是多少?请将答案对109+7取模后输出。
PS:不清楚期望是啥?为什么不问问神奇的百度呢?
Input
第一行一个数,表示数据组数T。
每组数据第一行一个整数n;接下来n行,每行两个数,表示li和ri。
数据组数T=100,满足:
−1≤n≤100−1≤n≤100
−1≤li≤ri≤104−1≤li≤ri≤104
其中70%的数据满足ri≤100。
Output
每组数据输出一行,每行仅包含一个数,表示期望。
假设答案为pq,请输出p×q−1 mod 109+7,此处q−1为q的逆元。
Sample Input
2
3
2 5
2 4
2 5
3
1 1
2 3
1 1
Sample Output
875000012
500000010
Hint
第二组数据的解释:序列只有两种情况(1,2,1)和(1,3,1),权值分别为2*1*2=4和3*1*3=9,答案为(4+9)/2,在模域下为500000010。

#include<iostream>
#include<cstdio>
#include<algorithm>
#define RG register
#define ll long long
#define mod 1000000007
using namespace std; int n;
ll l[], r[]; inline ll mpow ( ll a, ll b ) {
ll ans = ;
for ( ; b; b >>= , a = a * a % mod )
if ( b & ) ans = ans * a % mod;
return ans;
} int main ( ) {
int T;
scanf ( "%d", &T );
while ( T -- ) {
scanf ( "%d", &n );
ll sum = , MI = , MA = ;
for ( int i = ; i <= n; i ++ ) {
scanf ( "%I64d%I64d", &l[i], &r[i] );
sum = sum * ( r[i] - l[i] + ) % mod;
MI = max( l[i], MI );
MA = max( MA, r[i] );
}
ll ans = ;
for ( RG ll h = MI; h <= MA; h ++ ) {
ll sum1 = , sum2 = ;
for ( RG int i = ; i <= n; i ++ ) {
ll L = l[i], R = min ( h, r[i] );
L = h - L + , R = h - R + ;
sum1 = ( L + R ) * ( L - R + ) / * sum1 % mod;
}
for ( RG int i = ; i <= n; i ++ ) {
ll L = l[i], R = min ( h - , r[i] );
L = h - L + , R = h - R + ;
sum2 = ( L + R ) * ( L - R + ) / * sum2 % mod;
}
ans = ( ans + ( sum1 - sum2 + mod ) % mod ) % mod;
}
ans = ans * mpow( sum, mod - ) % mod;
printf ( "%I64d\n", ans );
}
return ;
}
【HDU】6410:序列期望的更多相关文章
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 5570 balls 期望 数学
balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5570 De ...
- poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP
poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...
- hdu 5159 Card (期望)
Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...
- hdu 5248 序列变换(二分枚举)
Problem Description 给定序列A={A1,A2,...,An}, 要求改变序列A中的某些元素,形成一个严格单调的序列B(严格单调的定义为:Bi<Bi+,≤i<N). 我们 ...
- hdu 5245 Joyful(期望的计算,好题)
Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to pain ...
- hdu 5256 序列变换 (LIS变形)
序列变换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- Maze HDU - 4035(期望dp)
When wake up, lxhgww find himself in a huge maze. The maze consisted by N rooms and tunnels connecti ...
- HDU 6348 序列计数 (树状数组 + DP)
序列计数 Time Limit: 4500/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
随机推荐
- XML-RPC笔记
1.什么是XML-RPC RPC(Remote Procedure Call)就是相当于提供了一种"远程接口"来供外部系统调用,常用于不同平台.不同架构的系统之间互相调用. XML ...
- npm的常用命令
npm install <name>安装nodejs的依赖包 例如npm install express 就会默认安装express的最新版本,也可以通过在后面加版本号的方式安装指定版本, ...
- Lithium中关键特性更新
Lithium中关键特性更新 1. Lithium特性更新概述 Lithium相对于Helium更新特性共27项,其中原有特性提升或增强13项,新增特性14项,如下表所示 特性类型 相对于Helium ...
- Bootstrap文件上传组件:bootstrap fileinput
为了上传预览pdf与图片特用此插件. 源码以及API地址: bootstrap-fileinput源码:https://github.com/kartik-v/bootstrap-fileinput ...
- bootstrap分页查询传递中文参数到后台(get方式提交)
<!--分页 --> <div style="width: 380px; margin: 0 auto; margin-top: 50px;"> <u ...
- 目标检测-基于Pytorch实现Yolov3(1)- 搭建模型
原文地址:https://www.cnblogs.com/jacklu/p/9853599.html 本人前段时间在T厂做了目标检测的项目,对一些目标检测框架也有了一定理解.其中Yolov3速度非常快 ...
- logging模块配置笔记
logging模块配置笔记 log文件的路径 #判断在当前的目录下是否有一个logs文件夹.没有则创建 log_dir = os.path.dirname(os.path.dirname(__file ...
- linux系统kill一些类名称相同的进程
jps | grep "Main" | awk '{print $1}' | xargs kill 将其中的 Main 替换为需要kill的进程名即可.
- Photon3Unity3D.dll 解析一
IPhotonPeerListener Photon客户端回调接口 1: //只要有来自Photon Server的事件就触发 2: public virtual void OnEvent( Eve ...
- 次短路经(dijsktra)
#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#defi ...