HDU 5481 Desiderium 动态规划
Desiderium
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5481
Description
There is a set of intervals, the size of this set is n.
If we select a subset of this set with equal probability, how many the expected length of intervals' union of this subset is?
We assume that the length of empty set's union is 0, and we want the answer multiply 2n modulo 109+7.
Input
The first line of the input is a integer T, meaning that there are T test cases.
Every test cases begin with a integer n ,which is size of set.
Then n lines follow, each contain two integers l,r describing a interval of [l,r].
1≤n≤100,000.
−1,000,000,000≤l≤r≤1,000,000,000.
Output
For every test case output the answer multiply 2n modulo 109+7.
Sample Input
2
1
0 1
2
0 2
1 3
Sample Output
1
7
HINT
题意
有一条数轴,还有一个区间的集合,集合大小为n。
现在等概率的从集合中选出集合的一个子集,求取出的子集的区间并集的期望长度。
空集的区间并长度被认为是0。
题解:
实际上计算的是所有子集的并集长度之和。
把坐标离散化之后,可以单独考虑每一小段区间在并集内部的出现次数,如果有mm个大区间覆盖这段小区间,就会发现当前仅当这mm个区间都不在子集中时,这一小段区间不会成为并集中的一部分,所以一共有2^n-2^m2
个子集包含这段小区间。把长度乘出现次数累计到答案里即可
@)1%KBO0HM418$J94$1R.jpg)
代码:
//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 300006
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* int p[maxn];
struct node{
int x,y;
};
node dp2[maxn];
bool cmp(node a,node b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
int dp[maxn];
void pre()
{
p[]=;
for(int i=;i<maxn;i++)
{
long long tmp=2LL*p[i-];
if(tmp>=mod) tmp-=mod;
p[i]=(int)tmp;
}
}
int main()
{
pre();
int t=read();
while(t--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
long long tmp=(long long)(p[i]-);
if(tmp<) tmp+=mod;
tmp*=(long long)(p[n-i]);
if(tmp>=mod) tmp%=mod;
dp[i]=(int)tmp;
}
for(int i=;i<n;i++)
{
scanf("%d%d",&dp2[i<<].x,&dp2[i<<|].x);
dp2[i<<].y=;dp2[i<<|].y=-;
}
sort(dp2,dp2+*n,cmp);
int ans1=;
ll ans2=;
for(int i=;i<*n-;i++)
{
int l=dp2[i].x,r=dp2[i+].x;
ans1+=dp2[i].y;
ans2+=(ll)(r-l)*(ll)dp[ans1];
if(ans2>=mod) ans2%=mod;
}
printf("%I64d\n",ans2);
}
return ;
}
HDU 5481 Desiderium 动态规划的更多相关文章
- [HDU 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n个任务集合,需要在T个时间单位内完成.每个任务集合有属性,属性为0的代表至少要完成1个 ...
- [HDU 1114] Piggy-Bank (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 简单完全背包,不多说. #include <cstdio> #include < ...
- [HDU 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- HDU 2571 命运 动态规划
命运 http://acm.hdu.edu.cn/showproblem.php?pid=2571 Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了!可谁能想到, ...
- 百度之星资格赛 hdu 4826 Labyrinth 动态规划
/********************* Problem Description 是一仅仅喜欢探险的熊.一次偶然落进了一个m*n矩阵的迷宫,该迷宫仅仅能从矩阵左上角第一个方格開始走,仅仅有走到右上 ...
- hdu 2059 龟兔赛跑(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2059 龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others) M ...
- HDU 1069 基础动态规划+排序
题意 给出n种立方体石头 当且仅当一块石头的底部宽度长度都小于一块石头的时候才能放在上面 问最高能放多高?石头不限数目 然而同样一种石头采用同样的摆放方式 两快相同石头一定无法进行放置 所以 一块石头 ...
- hdu 4571 floyd+动态规划
思路: 我们先求一遍floyd,将各点的最短距离求出,然后将点按si的升序排序.dp[i][k]表示第i个点在第j时间所获得的最大效益,那么 dp[i][k]=max(dp[ i ][ k ] , ...
- hdu 2583 permutation 动态规划
Problem Description Permutation plays a very important role in Combinatorics. For example ,1 2 3 4 ...
随机推荐
- echarts 问题2
加载图表的区域div必须单独给定class,此样式中必须还有宽和高,不然图表出来之后会有这样那样的问题
- .NET下文本相似度算法余弦定理和SimHash浅析及应用
余弦相似性 原理:首先我们先把两段文本分词,列出来所有单词,其次我们计算每个词语的词频,最后把词语转换为向量,这样我们就只需要计算两个向量的相似程度. 我们简单表述如下 文本1:我/爱/北京/ ...
- 【Grunt】
GRUNT The JavaScript Task Runnerhttp://gruntjs.com/ Grunt打造前端自动化工作流http://tgideas.qq.com/webplat/inf ...
- 【持续更新】D3 的学习资料
经常有朋友问哪里有关于 D3 的比较好的学习资料,现整理成此文.以后找到更多更好的,会不断更新本文. 我是在2013年开始接触 D3 的,当时就觉得这个工具很好玩.至今,学习资料整理了不少.如果有朋友 ...
- Android 数据传输之MessagePack使用
介绍过什么是MessagePack之后,就进行Android与MessagePack的使用. 在MessagePack的官网上介绍MessagePack与Java结合使用的都是使用Maven作为JAR ...
- Android学习笔记:TabHost 和 FragmentTabHost
TabHost 命名空间: android.widget.TabHost 初始化函数(必须在addTab之前调用): setup(); 包含两个子元素: 1.Tab标签容器TabWidget(@and ...
- win7远程链接ubuntu 桌面版
1.安装ubuntu 使用vagrant 添加了一个ubuntu12.04(xmanager好像只能控制最高这个版本,14.04没成功过) 2.安装xmanager 4 3.修改ubutu配置文件 s ...
- [GRYZ2015]足球联赛
问题描述 巴蜀中学新一季的足球联赛开幕了.足球联赛有n 只球队参赛,每赛季,每只球队要与其他球队各赛两场,主客各一场,赢一场得3 分,输一场不得分,平局两只队伍各得一分.英勇无畏的小鸿是机房的主力前锋 ...
- jquery 日期控件
控件官网: http://www.interidea.org/demo/icalendar.php#demohtml绑定控件 $("#startdate").icalendar({ ...
- Makefile编程
[个人体会]0.1 项目文件要合理分隔,功能模块分开放,分别设置Makefile自动编译, 0.2 源码和头文件分开放,一个或多个头文件对应一个源码文件. ...