PoPoQQQ要在電影院裏呆L分鐘,這段時間他要看小型電影度過。電影一共N部,每部都播放於若干段可能重疊的區間,PoPoQQQ決不會看同一部電影兩次。如今問他要看最少幾部電影才能度過這段時間? 注:必須看電影才能在電影院裏呆着,同時一場電影能夠在其播放區間內任意時間入場出場。N=20。每部電影的重複區間<=100。git
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=25;
const int maxn=1e3+5;
const int inf=0x7f7f7f7f;
int ta[nmax][maxn],te[nmax],cnt[nmax],dp[3000005];
int find(int a,int b){
int mx=dp[a-(1<<(b-1))],l=1,r=cnt[b],ans=0,mid;
while(l<=r){
mid=(l+r)>>1;
if(ta[b][mid]<=mx) ans=mid,l=mid+1;
else r=mid-1;
}
mx=max(mx,ta[b][ans]+te[b]);
return mx;
}
int main(){
int n=read(),t=read();
rep(i,1,n) {
te[i]=read(),cnt[i]=read();
rep(j,1,cnt[i]) ta[i][j]=read();
}
int se=(1<<n)-1,ans=inf,sm;
rep(i,1,se){
sm=0;
rep(j,1,n) if(i&(1<<(j-1))) ++sm,dp[i]=max(dp[i],find(i,j));
if(dp[i]>=t) ans=min(ans,sm);
}
if(ans==inf) puts("-1");else printf("%d\n",ans);
return 0;
}
/*
4 100
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0
*/
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決不會看同一部電影兩次。如今問他要看最少幾部電影才能度過這段時間? 注:必須看電影才能在電影院裏呆着,同時一場電影能夠在其播放區間內任意時間入場出場。this
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.