Description

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决不会看同一部电影两次。现在问他要看最少几部电影才能度过这段时间? 注:必须看电影才能在电影院里呆着,同时一场电影可以在其播放区间内任意时间入场出场。

Input

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.

Output

A single integer indicating the minimum number of movies that Bessieneeds to see to achieve her goal. If this is impossible output -1 instead.

Sample Input

4 100

50 3 15 30 55

40 2 0 65

30 2 20 90

20 1 0

Sample Output

3


这题我们设f[sta]代表已看的电影集合为sta,所能待到的最长时间。转移的时候枚举一个没有看过的电影,找到最近的开始时间,直接转移即可。

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=1e3;
int len[25],cnt[25];
int A[25][N+10],f[(1<<21)+10];
int find(int x,int i){//二分开始时间
int l=0,r=cnt[i],res=0;
while (l<=r){
int mid=(l+r)>>1;
if (x<A[i][mid]) r=mid-1;
else l=mid+1,res=mid;
}
return res;
}
int main(){
int n=read(),L=read(),Ans=inf;
for (int i=1;i<=n;i++){
len[i]=read(),cnt[i]=read();
for (int j=1;j<=cnt[i];j++) A[i][j]=read();
}
memset(f,255,sizeof(f));
f[0]=0;
for (int sta=0;sta<1<<n;sta++){
if (f[sta]==-1) continue;
if (f[sta]>=L){//统计答案
int res=0;
for (int s=sta;s;s-=lowbit(s)) res++;
Ans=min(Ans,res);
}
for (int i=1;i<=n;i++){
if (!(sta&(1<<(i-1)))){
int k=find(f[sta],i);
if (!k) continue;
f[sta|(1<<(i-1))]=max(f[sta|(1<<(i-1))],A[i][k]+len[i]);
}
}
}
printf("%d\n",Ans==inf?-1:Ans);
return 0;
}

[Usaco2015 Jan]Moovie Mooving的更多相关文章

  1. BZOJ3886 : [Usaco2015 Jan]Moovie Mooving

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

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

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

  3. 3890: [Usaco2015 Jan]Meeting Time( dp )

    简单的拓扑图dp.. A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了 时间复杂度O(m) --------------------------- ...

  4. [USACO15JAN]电影移动Moovie Mooving

    [USACO15JAN]电影移动Moovie Mooving 时间限制: 2 Sec  内存限制: 128 MB 题目描述 Bessie is out at the movies. Being mis ...

  5. [补档][Usaco2015 Jan]Grass Cownoisseur

    [Usaco2015 Jan]Grass Cownoisseur 题目 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过? (一个点在路 ...

  6. BZOJ3887 [Usaco2015 Jan] Grass Cownoisseur 【tarjan】【DP】*

    BZOJ3887 [Usaco2015 Jan] Grass Cownoisseur Description In an effort to better manage the grazing pat ...

  7. bzoj3887: [Usaco2015 Jan]Grass Cownoisseur

    题意: 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在路径中无论出现多少正整数次对答案的贡献均为1) =>有向图我们 ...

  8. BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP

    BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP Description In an effort to better manage t ...

  9. [bzoj3887][Usaco2015 Jan]Grass Cownoisseur_trajan_拓扑排序_拓扑序dp

    [Usaco2015 Jan]Grass Cownoisseur 题目大意:给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在 ...

随机推荐

  1. 【区间DP+好题】String painter

    https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定两个长度相同的字符串A,B.每次操作都能把A中的任意一个子段变成 ...

  2. [网络流24题] 方格取数问题(cogs 734)

    «问题描述:在一个有m*n 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意2 个数所在方格没有公共边,且取出的数的总和最大.试设计一个满足要求的取数算法.«编程任务:对于给定的方格棋 ...

  3. LOJ#539. 「LibreOJ NOIP Round #1」旅游路线

    n<=100,m<=1000的图,在此图上用油箱容量C<=1e5的车来旅行,旅行时,走一条边会耗一单伟油,在点i时,若油量<ci,则可以把油以pi的价格补到ci,pi<= ...

  4. spring boot项目自定义数据源,mybatisplus分页、逻辑删除无效解决方法

    Spring Boot项目中数据源的配置可以通过两种方式实现: 1.application.yml或者application.properties配置 2.注入DataSource及SqlSessio ...

  5. spring mvc随便接收list<objeect>参数

    在后台设定一个类,PersonList类: public class PersonList {private List<User> user; public List<User> ...

  6. 怎样删除Tomcat下已经部署的项目

    lz说的是把web项目部署到tomcat之中,要把它删除..很简单,找到webapps文件(tomcat的根目录)下把它删除即可.. 2.Tomcat 6.0\webapps\项目名 只要在把这个目录 ...

  7. mysql 排序order by可以根据权重,进行表达式计算。再排序

    1.select * from tbl_actor order by (follower_count+Recommend_weight)*weight_ratio desc limit 3; 2.or ...

  8. C++中使用Json的方法

    使用 C++ 处理 JSON 数据交换格式 一.摘要 JSON 的全称为:JavaScript Object Notation,顾名思义,JSON 是用于标记 Javascript 对象的,JSON官 ...

  9. [Qt总结篇]终端远程升级client

    环境: QT4.8.5 for Windows(Qt Creator+MinGW) 一.写在前面: 1.深度:鉴于C/C++的功底还远远不足,个人主要精力还是学习C/C++,所以没打算继续深入研究Qt ...

  10. 【智能家居篇】wifi网络结构(下)

    转载请注明出处:http://blog.csdn.net/Righthek 谢谢. 因为WIFI网络具有移动性,同一时候WIFI以无线电波作为传输媒介,这样的媒介本质上是开放的,且easy被拦截,不论 ...