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;
}

最新文章

  1. Java多线程
  2. 像黑客一样使用 Linux 命令行
  3. 用File判断D盘下面是否还有txt文件
  4. 从jquery源码中看类型判断和数组的一些操作
  5. jquery each遍历节点使用
  6. HTML &lt;fieldset&gt; 标签
  7. proxy改变this指向
  8. css/js(工作中遇到的问题)
  9. Extjs 中column的renderer使用方法
  10. UML类图新手入门级介绍
  11. mysql注册服务
  12. 疯狂学习java web2(css)
  13. NoSQL简要数据库
  14. perl 异步超时 打印错误
  15. hdu 4858 项目管理(STL集装箱)
  16. ng-file-upload(在单文件选择,并且通过点击“上传”按钮上传文件的情况下,如何在真正选择文件之前保留上一文件信息?)
  17. 轴对称 Navier-Stokes 方程组的一个点态正则性准则
  18. SpringBoot实现标准的OAuth服务提供商
  19. HTML中--定义header和footer高度中间自适应
  20. Linux环境下配置maven环境

热门文章

  1. MySQL:视图、触发器、存储过程、事务
  2. [USACO08NOV]时间管理Time Management
  3. POJ 3041_Asteroids
  4. [bzoj1207][HNOI2004]打鼹鼠_动态规划
  5. linux下crontab安装和使用(定时任务)
  6. Servlet的HTTP状态码
  7. cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64
  8. 详解ORACLE数据库的分区表
  9. html上传图片类型
  10. 制作svg动画