【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。
,我们先把每个M的贡献加起来最后除以每种情况的概率就是答案。#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 ...
随机推荐
- idea中tomcat乱码问题解决
在idea中经常遇到jsp的乱码问题,原因是编码不是UTF-8的问题,这次来彻底解决idea的编码问题 首先设置idea编辑器的编码: File-Setting设置如下 然后配置tomcat的编码问题 ...
- vue-cli使用说明
一.安装npm install -g vue-cli 推荐使用国内镜像 先设置cnpm npm install -g cnpm --registry=https://registry.npm.taob ...
- scrapy 爬虫踩过的坑(I)
问题1:正则表达式没问题,但是爬虫进不了item方法 分析: 1. 可能是下载不到list 页面的内容.可以用 scrapy shell url 进行测试 2. 可能是allowed_domains ...
- Codeforces 665E. Beautiful Subarrays (字典树)
题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意 ...
- Elasticsearch5.0 安装问题集锦【转】
转自 Elasticsearch5.0 安装问题集锦 - 代码&优雅着&生活 - 博客园http://www.cnblogs.com/sloveling/p/elasticsearch ...
- android sdcard 权限管理策略研究
自从android4.4 以来,第三方应用程序是不能再随便的访问sdcard了,从开发者的角度而言,研究一下android系统到底是怎么样来实现这样的控制还是比较有价值的. 首先分析下现状,现在已知, ...
- Mybatis的初步使用
MyBatis 是当下最流行的持久层框架,也是ORM框架,本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google ...
- Linux下的各类文件
.a文件是静态链接库文件.所谓静态链接是指把要调用的函数或者过程链接到可执行文件中,成为可执行文件的一部分.当多个程序都调用相同函数时,内存中就会存在这个函数的多个拷贝,这样就浪费了宝贵的内存资源.. ...
- C语言 五子棋2
#include<windows.h> #include<stdlib.h> #include<stdio.h> #include<conio.h> # ...
- Adsafe 导致win10 中窗口错位
域账号使用,出现上述情况,干掉后一切恢复正常... 还好家里的本地管理员账号使用一切正常,不然又被广告占领了