[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.

样例输入

4 100
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0

样例输出

3

提示

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的更多相关文章

  1. [bzoj3886] [USACO15JAN]电影移动Moovie Mooving

    题目链接 状压\(dp\). 注意到\(n\leq 20\)且每个只能用一次,所以很显然可以压缩每部电影看过没,记\(f[sta]\)为状态为\(sta\)时最多可以看多久. 转移时先枚举状态,然后枚 ...

  2. P3118 [USACO15JAN]Moovie Mooving G

    P3118 [USACO15JAN]Moovie Mooving G Link 题目描述 Bessie is out at the movies. Being mischievous as alway ...

  3. [USACO15JAN]Moovie Mooving G

    [USACO15JAN]Moovie Mooving G 状压难题.不过也好理解. 首先我们根据题意: she does not want to ever visit the same movie t ...

  4. Luogu3118:[USACO15JAN]Moovie Mooving

    题面 传送门 Sol 设\(f[S]\)表示看过的电影集合为\(S\),当前电影的最大结束时间 枚举电影和电影的开始时间转移 可以对开始时间\(sort\) 二分一下转移即可 # include &l ...

  5. BZOJ3886 : [Usaco2015 Jan]Moovie Mooving

    f[i]表示用i集合内的电影可以达到的最长时间 f[i]向f[i|(1<<j)]更新,此时的时间为第j部电影在f[i]前的最晚上映时间 先排序一遍离散化后用前缀最大值解决 时间复杂度$O( ...

  6. 【bzoj3886】[Usaco2015 Jan]Moovie Mooving 状态压缩dp+二分

    题目描述 Bessie is out at the movies. Being mischievous as always, she has decided to hide from Farmer J ...

  7. [Usaco2015 Jan]Moovie Mooving

    Description Bessie is out at the movies. Being mischievous as always, she has decided to hide from F ...

  8. DP测试总结

    T1:三取方格数 题目描述 设有N*N的方格图,我们将其中的某些方格填入正整数,而其他的方格中放入0.某人从图得左上角出发,可以向下走,也可以向右走,直到到达右下角.在走过的路上,他取走了方格中的数. ...

  9. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

随机推荐

  1. (原创)如何在性能测试中自动生成并获取Oracle AWR报告

    版权声明:本文为原创文章,转载请先联系并标明出处 由于日常使用最多的数据库为Oracle,因此,最近又打起了Oracle的AWR报告的主意. 过去我们执行测试,都是执行开始和结束分别手动建立一个快照, ...

  2. centOS的命令行与图形页面之间的转换

    .命令行 -> 图形界面 注意:在安装CentOS7的时候要添加GUI图形界面,否则没有效果. # startx

  3. 用CSS3实现饼状loading效果

    原文地址:http://visugar.com/2017/05/17/CSS3%E9%A5%BC%E7%8A%B6loading%E6%95%88%E6%9E%9C/ 写在前面 (附录有源码及效果) ...

  4. StringTokenizer使用笔记

    StringTokenizer 基本使用 笔者最近在做算数表达式的逆波兰式转换和解析,原始表达式为String类型,在使用StringTokenizer 之前笔者的解决思路是 将原始表达式->转 ...

  5. php中for循环的应用1

    for 循环是 PHP 中最复杂的循环结构.它的行为和 C 语言的相似.在PHP中使用的是执行相同的代码集的次数. for 循环的语法是: for (expr1; expr2; expr3)state ...

  6. bash下. : () {} [] [[]] (())的解释 (非原创,侵删)

    Copy from http://blog.chinaunix.net/uid-20380484-id-1692999.html bash下有很多像{}.[]等一些符号命令,下面是我对一些常用的符号命 ...

  7. 细说"回车"和"换行"的故事

    引言 最近在php还有c#以及memcache的shell当中经常看到\r\n的写法,刚开始还没注意, 不过后面感觉这样写有些不对头,\r表示回车  \n表示换行,那这样不是换行了两次吗? 为了解决疑 ...

  8. netty基础--基本收发

    使用maven构建一个基本的netty收发应用,作为其他应用的基础.客户端使用packet sender工具. 1  添加netty依赖 1  maven netty依赖 <dependency ...

  9. ES6解构赋值详解

    文章转载自:http://www.zhufengpeixun.cn/article/167 解构赋值(destructuring assignment)语法是一个 Javascript 表达式,这种语 ...

  10. [HDU1004] Let the balloon rise - 让气球升起来

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...