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 MB
Submit: 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

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 Bessie

needs 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

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

Gold&鸣谢18357

时间: 2024-08-19 21:22:47

bzoj3886: [Usaco2015 Jan]Moovie Mooving的相关文章

BZOJ 3887[Usaco2015 Jan]Grass Cownoisseur

题面: 3887: [Usaco2015 Jan]Grass Cownoisseur Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 237  Solved: 130[Submit][Status][Discuss] Description In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow pat

bzoj3887: [Usaco2015 Jan]Grass Cownoisseur

题意: 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在路径中无论出现多少正整数次对答案的贡献均为1) =>有向图我们先考虑缩点.然后观察缩点后的图可以发现新的路径中必定只有一条边是反向的才符合条件.那么我们可以联想到某道最短路的题将边反向存一遍后分别从s和t跑一跑.那么这里bfs跑一跑就行了.然后有一个坑点:这种重建图的注意es和edges不然es会在中途就被修改掉了... #include<cstdio> #

3890: [Usaco2015 Jan]Meeting Time( dp )

简单的拓扑图dp.. A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了 时间复杂度O(m) ---------------------------------------------------------------- #include<bits/stdc++.h> #define clr(x, c) memset(x, c, sizeof(x)) #define rep(i, n) for(int i = 0; i < n; ++

线段树 BZOJ3888 [Usaco2015 Jan]Stampede

3888: [Usaco2015 Jan]Stampede Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 253  Solved: 81[Submit][Status][Discuss] Description Farmer John's N cows (1 <= N <= 50,000) appear to be stampeding along the road at the front of FJ's farm, but they are

[USACO15JAN]电影移动Moovie Mooving

[USACO15JAN]电影移动Moovie Mooving 挺无语的状态压缩题目,太显然了. \(f[i]\)表示状态为i的最远到达的距离. 然后暴力枚举每一个可行的点. 然后二分一下即可.. /*header*/ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <cmath&g

【BZOJ3886】【Usaco2015 Jan】Moovie Mooving 状态压缩 动态规划

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44040735"); } 题意: PoPoQQQ要在电影院里呆L分钟,这段时间他要看小型电影度过.电影一共N部,每部都播放于若干段可能重叠的区间,PoPoQQQ决不会看同一部电影两次.现在问他要看最少几部电影才能度过这段时间? 注:必

【BZOJ3888】【Usaco2015 Jan】Stampede 线段树判区间覆盖

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44066313"); } 题意: PoPoQQQ站在原点上向y轴正半轴看,然后有一群羊驼从他眼前飞过.这些羊驼初始都在第二象限,尾巴在(Xi,Yi),头在(Xi+1,Yi),每Ci秒向右走一个单位. PoPoQQQ能看见一匹羊驼当且仅

BZOJ3888 [Usaco2015 Jan]Stampede

我们只要把每头牛开始遮挡视线和结束遮挡视线的时间点都搞出来就好= = 再按照y轴排序...然后变成线段覆盖了..线段树搞一下就好了? 1 /************************************************************** 2 Problem: 3888 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:1204 ms 7 Memory:22684 kb 8 ****************

【BZOJ3889】【Usaco2015 Jan】Cow Routing 双键值最短路

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44064091"); } 题意: 从样例讲起. 第一行 s,t,m表示:起点,终点,m条航线. 然后m组,每组第一行len,n表示这条航线的代价, 这类似于公交车,只要用了就花这些钱,但是用多少都这些钱. 注意是单向边. 举例: 23