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 ...
随机推荐
- 1521. War Games 2(线段树解约瑟夫)
1521 根据区间和 来确定第k个数在哪 #include <iostream> #include<cstdio> #include<cstring> #inclu ...
- ☀Chrome模拟移动端浏览器
- mysql中php生成唯一ID
<?php //uniqid官方手册 function create_guid($namespace = '') { static $guid = ''; $uid = uniqid(" ...
- lightoj 1018 (状态压缩DP)
设dp[s]表示状态s下所需要的线段的个数,s的二进制中第x位为1就表示该状态下第x个点没被线段覆盖.需要预处理出来在任意两点之间连线所覆盖点的状态O(n^3),然后记忆化搜索即可. #include ...
- 陈灯WGF双缓冲绘图框架
“木丸子童屋”,专售各类儿童玩具,价格优惠,请大家多多支持:http://shop65552598.taobao.com/ WGF(windows graphic foundation)为window ...
- 玩一个:可以显示任何xml树结构的xaml定义
学习中, 玩一玩. 效果如下.Xaml随后. <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentatio ...
- eclipse配置tomcat加大内存的方法
双击tomcat -Dcatalina.base="E:\work\whykt\.metadata\.plugins\org.eclipse.wst.server.core\tmp0&quo ...
- NOIP2005 篝火晚会
篝火晚会 (fire.pas/c/cpp) [问题描述] 佳佳刚进高中,在军训的时候,由于佳佳吃苦耐劳,很快得到了教官的赏识,成为了“小教官”.在军训结束的那天晚上,佳佳被命令组织同学们进行篝火晚会. ...
- 50道经典的JAVA编程题(46-50)
50道经典的JAVA编程题(46-50),最后五道题了,这是一个美妙的过程,编程真的能让我忘掉一切投入其中,感觉很棒.今天下午考完微机原理了,大三上学期就这样度过了,这学期算是解放了,可是感觉我还是没 ...
- ubuntu免验证登陆权限问题
由于经常ssh到服务器,每次输入密码很烦.就传了本机公钥到服务器. 和所有教程将的一样,做起来挺简单的. 本机ssh-keygen -t rsa生成公钥和密钥. 将公钥传至服务器,用户目录下.ssh/ ...