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 ...
随机推荐
- Java web 项目 tomcat部署方式.
本地做Java Web项目的时候常常会用到tomcat部署测试的问题, 这里介绍项目的部署方法: 1,配置文件的形式: 例如: 你的项目目录为:f:\workspaces\MyProject,此时使用 ...
- 8款JS框架比较
Dojo Dojo 是目前最为强大的JS框架,它在自己的 Wiki 上给自己下了一个定义,Dojo 是一个用 JavaScript 编写的开源的DHTML工具箱.Dojo 很想做一个“大一统” ...
- 【highcharts】
zoomType positioner
- webapp开发经验和资料
开发经验: 开发资料: 1. http://xuui.net/librarys/webapps/webapp-development-of-commonly-used-code-snippets.ht ...
- FirstOrDefault
FirstOrDefault:取序列中满足条件的第一个元素,如果没有元素满足条件,则返回默认值(对于可以为null的对象,默认值为null,对于不能为null的对象,如int,默认值为0)
- UVA 10585 Center of symmetry
题意:给出一个点集,问这个集合有没有中心点使点集对称,这个点可以是点集中的点也可以不是点集的点. 解法:一开始我枚举每两个点连线的中点……结果T了orz当时也不知道怎么想的…… 将点按横坐标排序,如果 ...
- java 多线程下载
import java.io.ByteArrayOutputStream; import java.io.InputStream; public class StreamTool { /** * 把一 ...
- HDU 5617 Jam's maze 巧妙DP
题意:给你一个字符矩阵,从(1,1)到(n,n)有很多种走法,每一种走法形成一个字符串,问有多少种走法形成的字符串是回文的 分析:(粘贴BC题解) 的是回文串,有人会想到后缀数组自动机马拉车什么的,其 ...
- chrome启用本地文件
chrome禁止本地浏览时加载本地其他文件,可以采用添加启动参数的方式来支持 添加参数为 --allow-file-access-from-files 或者 --disable-web-securi ...
- case中定义变量
1.c语言switch/case中定义变量 case 0: int b = 0 ; printf("0");break; case 1: printf("1" ...