bzoj3886: [Usaco2015 Jan]Moovie Mooving
Posted BBChq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj3886: [Usaco2015 Jan]Moovie Mooving相关的知识,希望对你有一定的参考价值。
题意:
PoPoQQQ要在电影院里呆L分钟,这段时间他要看小型电影度过。电影一共N部,每部都播放于若干段可能重叠的区间,PoPoQQQ决不会看同一部电影两次。现在问他要看最少几部电影才能度过这段时间? 注:必须看电影才能在电影院里呆着,同时一场电影可以在其播放区间内任意时间入场出场。N=20。每部电影的重复区间<=100。
=>N=20。那么我们还是考虑二进制枚举。转移方程类似。时间复杂度类似。哎呀套路啊。。。
#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 */
3886: [Usaco2015 Jan]Moovie Mooving
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 166 Solved: 105
[Submit][Status][Discuss]
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
Output
Sample Input
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0
Sample Output
SOLUTION NOTES:
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.
HINT
Source
以上是关于bzoj3886: [Usaco2015 Jan]Moovie Mooving的主要内容,如果未能解决你的问题,请参考以下文章
BZOJ 3887[Usaco2015 Jan]Grass Cownoisseur
线段树 BZOJ3888 [Usaco2015 Jan]Stampede
BZOJ-3890: [Usaco2015 Jan]Meeting Time (背包DP)
BZOJ3887: [Usaco2015 Jan]Grass Cownoisseur