[USACO15JAN]电影移动Moovie Mooving
[USACO15JAN]电影移动Moovie Mooving
时间限制: 2 Sec 内存限制: 128 MB
题目描述
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).
奶牛贝西想连续看L (1 <= L <= 100,000,000)分钟的电影,有 N (1 <= N <= 20)部电影可供选择,每部电影会在一天的不同时段放映。
贝西可以在一部电影播放过程中的任何时间进入或退出放映厅。但她不愿意重复看到一部电影,所以每部电影她最多看到一次。她也不能在看一部电影的过程中,换到另一个正在播放相同电影的放映厅。
请帮贝西计算她能够做到从0到L分钟连续不断地观看电影,如果能,请计算她最少看几部电影就行了。
输入
The first line of input contains N and L.
The next N lines each describe a movie. They begin with its integer duration, D (1 <= D <= L) and the number of showtimes, C (1 <= C <= 1000). The remaining C integers on the same line are each in the range 0..L, and give the starting time of one of the showings of the movie. Showtimes are distinct, in the range 0..L, and given in increasing order.
输出
A single integer indicating the minimum number of movies that Bessie
needs to see to achieve her goal. If this is impossible output -1
instead.
样例输入
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0
样例输出
提示
Bessie should attend the first showing of the fourth movie from time 0 to time 20. Then she watches the first showing of the first movie
from time 20 to time 65. Finally she watches the last showing of the second movie from time 65 to time 100.
题解:
因为每个电影都只能看一次,再看n的范围,果断状压dp。
f[i]表示当前i状态下所能够达到的最大时间点。
每次找到一个不在i状态下的电影,然后找到在f[i]时刻看第j部电影可以达到的最大时间。
判断一下f[i|t[j]]是否达到了t,如果是,就更新一下答案就可以了。
具体看代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
using namespace std;
int n,m,cnt,ans=;
int f[<<],t[],d[],a[][],c[];
int find(int x,int t)
{
int l=,r=c[x],s=;
while(l<=r)
{
int mid=(l+r)>>;
if(a[x][mid]>t)
{
r=mid-;
}
else
{
s=mid;
l=mid+;
}
}
if(s==)return ;
if(a[x][s]+d[x]>=t)return a[x][s]+d[x];
else return ;
}
int lowbit(int x)
{
return x&(-x);
}
void judge(int x)
{
int i,p=;
for(i=x;i;i-=lowbit(i))p++;
ans=min(ans,p);
return;
}
int main()
{
int i,j;
scanf("%d%d",&n,&m);
cnt=(<<n)-;
for(i=; i<=n; i++)t[i]=<<(i-);
for(i=; i<=n; i++)
{
scanf("%d%d",&d[i],&c[i]);
for(j=; j<=c[i]; j++)
scanf("%d",&a[i][j]);
}
for(i=; i<=cnt; i++)
{
for(j=; j<=n; j++)
{
if(!(i&t[j]))
{
f[i|t[j]]=max(f[i|t[j]],find(j,f[i]));
if(f[i|t[j]]>=m)
{
judge(i|t[j]);
}
}
}
}
if(ans==)cout<<-;
else cout<<ans;
return ;
}
[USACO15JAN]电影移动Moovie Mooving的更多相关文章
- [bzoj3886] [USACO15JAN]电影移动Moovie Mooving
题目链接 状压\(dp\). 注意到\(n\leq 20\)且每个只能用一次,所以很显然可以压缩每部电影看过没,记\(f[sta]\)为状态为\(sta\)时最多可以看多久. 转移时先枚举状态,然后枚 ...
- P3118 [USACO15JAN]Moovie Mooving G
P3118 [USACO15JAN]Moovie Mooving G Link 题目描述 Bessie is out at the movies. Being mischievous as alway ...
- [USACO15JAN]Moovie Mooving G
[USACO15JAN]Moovie Mooving G 状压难题.不过也好理解. 首先我们根据题意: she does not want to ever visit the same movie t ...
- Luogu3118:[USACO15JAN]Moovie Mooving
题面 传送门 Sol 设\(f[S]\)表示看过的电影集合为\(S\),当前电影的最大结束时间 枚举电影和电影的开始时间转移 可以对开始时间\(sort\) 二分一下转移即可 # include &l ...
- BZOJ3886 : [Usaco2015 Jan]Moovie Mooving
f[i]表示用i集合内的电影可以达到的最长时间 f[i]向f[i|(1<<j)]更新,此时的时间为第j部电影在f[i]前的最晚上映时间 先排序一遍离散化后用前缀最大值解决 时间复杂度$O( ...
- 【bzoj3886】[Usaco2015 Jan]Moovie Mooving 状态压缩dp+二分
题目描述 Bessie is out at the movies. Being mischievous as always, she has decided to hide from Farmer J ...
- [Usaco2015 Jan]Moovie Mooving
Description Bessie is out at the movies. Being mischievous as always, she has decided to hide from F ...
- DP测试总结
T1:三取方格数 题目描述 设有N*N的方格图,我们将其中的某些方格填入正整数,而其他的方格中放入0.某人从图得左上角出发,可以向下走,也可以向右走,直到到达右下角.在走过的路上,他取走了方格中的数. ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
随机推荐
- WPF 自定义ColorDialog DropDownCustomColorPicker
今天分享一个 WPF 版的ColorDialog,该控件源自 这里,不过笔者已经该控件做了大量的修改工作,以适应自己的产品需求,闲话少说,先看看效果图: 1.DropDownCustomColorPi ...
- Ajaxfileupload 总结(包括插件处理json格式bug的解决方案)
Ajaxfileupload 是一款轻量级js的上传插件,简单容易上手,今天简单学习了下. 1,引用jquery和Ajaxfileupload .js <script src="~/S ...
- scala读取jar包外配置文件的方式
在scala的开发过程中,经常会修改程序的参数,将这些参数放到配置文件中避免了重复编译,打包的过程 这里给出读取配置文件的三种方式 方式一: 这是最常见的读取配置文件方式 val postgprop ...
- HDU4704Sum 费马小定理+大数取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4704 题目大意: 看似复杂,其实就是求整数n的划分数,4=1+1+2和4=1+2+1是不同的.因而可 ...
- Windows安装Mysql5.7.10绿色版
今天在Windows上安装Mysql的时候,去官网上下了一个最新版本的Mysql5.7.10绿色版,但是之前网上安装方式都过时了,比如会报一些常见的错误“[ERROR] Fatal error: Ca ...
- 编写自己的一个简单的web容器(一)
在之前的博客中我更大家说过Http协议是对tcp协议的封装,其底层还是使用tcp协议来进行数据传出的,浏览器实际上就是一个Socket客户端,今天呢我们就开始着手利用ServerSocket来编写一个 ...
- MHA在线切换的步骤及原理
在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...
- 将非官方扩展程序加入chrome的白名单
参考来源:http://xclient.info/a/1ddd2a3a-d34b-b568-c0d0-c31a95f0b309.html com.google.Chrome.mobileconfig ...
- XCode 出现 is missing from working copy文件一直红色情况解决方法
解决方案:1.打开终端2.cd 到警告所提示的文件夹下3.执行命令svn rm 丢失文件的名称4.回车
- WPF自动更新程序
WPF AutoUpdater 描述: WPF+MVVM实现的自动更新程序 支持更新包文件验证(比较文件MD5码) 支持区分x86与x64程序的更新 支持更新程序的版本号 支持执行更新策略 截图: 使 ...