【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
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
随机推荐
- Git使用规范(三)
今天我们来介绍一下Git的一些操作,这个里面主要是一些我们平时遇到的一些问题 1.当我进入了一个分支的是时候,我在查看git log的时候,为什么会有别人的信息,我一直以为 这个是查看分支提交情况, ...
- WPF 为 PasswordBox 控件添加水印,最低级版
原因也很直接,老板需要,一开始为TextBox发愁,就找了这个控件凑合用,至于版权什么的,内部工具也不卖钱,而且我不懂英文,也就无视了: Extended WPF Toolkit™ Community ...
- 在同一台机器上启动多个tomcat服务(转)
转载:https://blog.csdn.net/wangxy799/article/details/53957770 1.案例:配置一台机上配置三个Tomcat 2.方法1:[只用修改第一个以外To ...
- Lvm linux磁盘分区管理(多个分区合并成一个)
备份# rsync -avP -e ssh /data qqmap@10.173.139.100:/data1/qqmap/backup/10.234.22.143卸载# umount /data / ...
- 南京Uber优步司机奖励政策(12月14日到12月20日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Python科学计算器(计算器)
说明 该计算器主要是为了练习正则表达式以及python基础所写:代码比较low! 运行过程 请输入你的计算公式, 计算器会将计算结果输出到屏幕上(此处会打印步骤); 退出(exit/quit) MyC ...
- 利尔达CC3200模块第一篇之-wlan_ap例程测试
1. 本次采用利尔达的CC3200模块,CC3200主时钟80M,内部没有flash,必须外接SPI Flash.本次测试采用利尔达科技的CC3200的底板和模块(左边).烧写连接VCC, GND, ...
- centos配置ip地址 添加多个ip地址的方法
操作如下,登陆SSH: vi /etc/sysconfig/network-scripts/ifcfg-eth0: 第二个IP,就是 vi /etc/sysconfig/network-scripts ...
- 397. Longest Continuous Increasing Subsequence
Description Give an integer array,find the longest increasing continuous subsequence in this array. ...
- 227. Mock Hanoi Tower by Stacks【LintCode java】
Description In the classic problem of Towers of Hanoi, you have 3 towers and N disks of different si ...