[bzoj3886] [USACO15JAN]电影移动Moovie Mooving
状压\(dp\)。
注意到\(n\leq 20\)且每个只能用一次,所以很显然可以压缩每部电影看过没,记\(f[sta]\)为状态为\(sta\)时最多可以看多久。
转移时先枚举状态,然后枚举没看过的电影,二分出一个小于\(f[sta]\)的时间点进行转移。
答案就是所有大于\(L\)的状态的\(1\)的个数的最小值。
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define int long long
void read(int &x){
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';x*=f;
}
#define write(x) printf("%lld\n",x)
#define maxn 1002
int f[(1<<20)+5],t[2001],s[21][1005],n,ed,cnt[(1<<20)+5],ans=1e9;
int calc(int x){
int res=0;
while(x) res+=(x&1),x>>=1;
return res;
}
signed main(){
//freopen("testdata(1).in","r",stdin);
read(n),read(ed);
for(int i=1;i<=n;i++) {
read(t[i]),read(s[i][0]);
for(int j=1;j<=s[i][0];j++) read(s[i][j]);
}
memset(f,-1,sizeof f);f[0]=0;
for(int i=0;i<(1<<n);i++) cnt[i]=calc(i);
for(int i=0;i<(1<<n);i++){
for(int j=1;j<=n;j++)
if(!(i&(1<<(j-1)))){
int p=upper_bound(s[j]+1,s[j]+s[j][0]+1,f[i])-s[j];
if(p>1) f[i|(1<<(j-1))]=max(f[i|(1<<(j-1))],s[j][p-1]+t[j]);
else f[i|(1<<(j-1))]=max(f[i|(1<<(j-1))],f[i]);
}
if(f[i]>=ed) ans=min(ans,cnt[i]);
}
if(ans==1e9) puts("-1");
else write(ans);
return 0;
}
[bzoj3886] [USACO15JAN]电影移动Moovie Mooving的更多相关文章
- [USACO15JAN]电影移动Moovie Mooving
[USACO15JAN]电影移动Moovie Mooving 时间限制: 2 Sec 内存限制: 128 MB 题目描述 Bessie is out at the movies. Being mis ...
- 【bzoj3886】[Usaco2015 Jan]Moovie Mooving 状态压缩dp+二分
题目描述 Bessie is out at the movies. Being mischievous as always, she has decided to hide from Farmer J ...
- P3118 [USACO15JAN]Moovie Mooving G
P3118 [USACO15JAN]Moovie Mooving G Link 题目描述 Bessie is out at the movies. Being mischievous as alway ...
- [USACO15JAN]Moovie Mooving G
[USACO15JAN]Moovie Mooving G 状压难题.不过也好理解. 首先我们根据题意: she does not want to ever visit the same movie t ...
- BZOJ3886 : [Usaco2015 Jan]Moovie Mooving
f[i]表示用i集合内的电影可以达到的最长时间 f[i]向f[i|(1<<j)]更新,此时的时间为第j部电影在f[i]前的最晚上映时间 先排序一遍离散化后用前缀最大值解决 时间复杂度$O( ...
- Luogu3118:[USACO15JAN]Moovie Mooving
题面 传送门 Sol 设\(f[S]\)表示看过的电影集合为\(S\),当前电影的最大结束时间 枚举电影和电影的开始时间转移 可以对开始时间\(sort\) 二分一下转移即可 # include &l ...
- [Usaco2015 Jan]Moovie Mooving
Description Bessie is out at the movies. Being mischievous as always, she has decided to hide from F ...
- DP测试总结
T1:三取方格数 题目描述 设有N*N的方格图,我们将其中的某些方格填入正整数,而其他的方格中放入0.某人从图得左上角出发,可以向下走,也可以向右走,直到到达右下角.在走过的路上,他取走了方格中的数. ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
随机推荐
- WebSocket协议 8 问
WebSocket是一种比较新的协议,它是伴随着html5规范而生的,虽然还比较年轻,但大多主流浏览器都已经支持.它使用方面.应用广泛,已经渗透到前后端开发的各种场景中. 对http一问一答中二式流程 ...
- 二、html篇
1.<br/> 有时css实现换行比较麻烦,可以使用该标签进行换行. 2.<strong></strong> <ins></ins> & ...
- Mina 组件介绍之 IoAcceptor 与 IoConnector
在网络通信中,Socket通信的双方分为服务端与客户端,在Java NIO 的实现中采用Socket/ServerSocket, SocketChannel/ServerSocketChannel分别 ...
- Python的Bottle框架中实现最基本的get和post的方法的教程
这篇文章主要介绍了Python的Bottle框架中实现最基本的get和post的方法的教程,Bottle框架在Python开发者中的人气很高,需要的朋友可以参考下 1.GET方式: # -*- cod ...
- php+sqlserver处理读取decimal 类型数据,不满1的数字会去掉0的问题
php+sqlserver处理读取decimal 类型数据,如果数据不满1,会去掉0的问题.比如读取的数据是 0.05,会显示 .05 function convert_number($number) ...
- Python3爬虫(十三) 爬取动态页之Selenium
Infi-chu: http://www.cnblogs.com/Infi-chu/ Python提供了很多模拟浏览器运行的库,比如:Selenium.Splash等 1.常用的引用 from sel ...
- 查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分
SELECT L.C# As 课程ID,L.score AS 最高分,R.score AS 最低分 FROM SC L ,SC AS R WHERE L.C# = R.C# and L.score = ...
- .net core 新建一个web api 的步骤 初级
1.使用VS2017 选择 .net core web应用程序. 2.选择web api(空). 3.如果需要用iis express调试,则需要修改 program.cs. 4.在Controlle ...
- linux mysql root 忘记密码了,完美解决-费元星站长
修改MySQL的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables 保存配置文件后,重启MySQL服务 service mysqld rest ...
- 【数据结构】 Queue 的简单实现
[数据结构] Queue 的简单实现 public class XQueue<T> { /// <summary> /// 第一个元素 /// </summary> ...