【bzoj3886】[Usaco2015 Jan]Moovie Mooving 状态压缩dp+二分
题目描述
Bessie is out at the movies. Being mischievous as always, she has decided to hide from Farmer John for L (1 <= L <= 100,000,000) minutes, during which time she wants to watch movies continuously. She has N (1 <= N <= 20) movies to choose from, each of which has a certain duration and a set of showtimes during the day. Bessie may enter and exit a movie at any time during one if its showtimes, but she does not want to ever visit the same movie twice, and she cannot switch to another showtime of the same movie that overlaps the current showtime. Help Bessie by determining if it is possible for her to achieve her goal of watching movies continuously from time 0 through time L. If it is, determine the minimum number of movies she needs to see to achieve this goal (Bessie gets confused with plot lines if she watches too many movies).
PoPoQQQ要在电影院里呆L分钟,这段时间他要看小型电影度过。电影一共N部,每部都播放于若干段可能重叠的区间,PoPoQQQ决不会看同一部电影两次。现在问他要看最少几部电影才能度过这段时间? 注:必须看电影才能在电影院里呆着,同时一场电影可以在其播放区间内任意时间入场出场。
输入
输出
样例输入
4 100
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0
样例输出
3
题解
状态压缩dp
设f[i]为状态i时最多能持续的时间。
那么就有f[i] = max(f[i] , a[j][k] + t[j]) (i&(1<<(j-1))==1,k为第一个使得a[j][k]>=f[i ^ (1 << (j - 1))]的数)。
于是二分查找即可,时间复杂度O(2^n*n*logd),看似很大,而亲测可过。
#include <cstdio>
#include <algorithm>
using namespace std;
int f[1050000] , t[21] , d[21] , a[21][1001] , num[1050000];
int search(int p , int x)
{
int l = 1 , r = d[p] , mid , ans = -1;
while(l <= r)
{
mid = (l + r) >> 1;
if(a[p][mid] <= x)
ans = mid , l = mid + 1;
else r = mid - 1;
}
return ans;
}
int main()
{
int n , m , i , j , k , ans = 0x7fffffff;
scanf("%d%d" , &n , &m);
for(i = 1 ; i <= n ; i ++ )
{
scanf("%d%d" , &t[i] , &d[i]);
for(j = 1 ; j <= d[i] ; j ++ )
scanf("%d" , &a[i][j]);
}
for(i = 1 ; i < 1 << n ; i ++ )
{
for(j = 1 ; j <= n ; j ++ )
{
if(i & (1 << (j - 1)))
{
k = search(j , f[i ^ (1 << (j - 1))]);
if(k != -1)
f[i] = max(f[i] , a[j][k] + t[j]);
}
}
}
for(i = 1 ; i < 1 << n ; i ++ )
{
num[i] = num[i - (i & (-i))] + 1;
if(f[i] >= m)
ans = min(ans , num[i]);
}
printf("%d\n" , ans == 0x7fffffff ? -1 : ans);
return 0;
}
【bzoj3886】[Usaco2015 Jan]Moovie Mooving 状态压缩dp+二分的更多相关文章
- BZOJ3886 : [Usaco2015 Jan]Moovie Mooving
f[i]表示用i集合内的电影可以达到的最长时间 f[i]向f[i|(1<<j)]更新,此时的时间为第j部电影在f[i]前的最晚上映时间 先排序一遍离散化后用前缀最大值解决 时间复杂度$O( ...
- BFS+状态压缩DP+二分枚举+TSP
http://acm.hdu.edu.cn/showproblem.php?pid=3681 Prison Break Time Limit: 5000/2000 MS (Java/Others) ...
- 【bzoj3312】[Usaco2013 Nov]No Change 状态压缩dp+二分
题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 ...
- [Usaco2015 Jan]Moovie Mooving
Description Bessie is out at the movies. Being mischievous as always, she has decided to hide from F ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
随机推荐
- Touch table
On this page I present the results of my touch action research. I concentrated on the few basic acti ...
- Java设计模式(15)——行为模式之策略模式(Strategy)
一.概述 概念 UML简图 角色 二.实践 我们先将上述的UML图的抽象情况下的代码写出,然后再给出一个具体的例子 策略接口——当然如果有一些公共的行为,应当使用抽象类! /** * 策略接口 * * ...
- tomcat8.5配置高并发
最近部署的tomcat应用,有一天压测的时候,测试一致反馈下载不了,结果查看日志才发现如下错误: INFO: Maximum number of threads (200) created for c ...
- 北京Uber优步司机奖励政策(3月26日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- cf#516C. Oh Those Palindromes(最多回文子串的字符串排列方式,字典序)
http://codeforces.com/contest/1064/problem/C 题意:给出一个字符串,要求重新排列这个字符串,是他的回文子串数量最多并输出这个字符串. 题解:字典序排列的字符 ...
- Appium(Python)驱动手机Chrome浏览器
手机Chrome浏览器访问淘宝H5与在电脑上访问淘宝H5是一摸一样的: 第一种方法: 直接在电脑Chrome浏览器上打开F12: 第二种方法: 手机连接电脑后, 在手机Chrome浏览器上打开淘宝H5 ...
- 定时任务 linux crontab 学习整理
1. 定时任务命令概念 crontab命令用于设置周期性被执行的指令.即设定脚本 按照规定时间执行相关的操作. 2.定时任务书写规范 * * * ...
- lintcode373 奇偶分割数组
奇偶分割数组 分割一个整数数组,使得奇数在前偶数在后. 您在真实的面试中是否遇到过这个题? Yes 样例 给定 [1, 2, 3, 4],返回 [1, 3, 2, 4]. 我的方法:设定两个数组,分别 ...
- LeetCode 120——三角形最小路径和
1. 题目 2. 解答 详细解答方案可参考北京大学 MOOC 程序设计与算法(二)算法基础之动态规划部分. 从三角形倒数第二行开始,某一位置只能从左下方或者右下方移动而来,因此,我们只需要求出这两者的 ...
- ElasticSearch 2.0以后的改动导致旧的资料和书籍需要订正的部分
id原先是可以通过path指定字段的 "thread": { "_id" : { "path" : "thread_id" ...