[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一问一答中二式流程 ...
- 微信小程序 提示框延时跳转
wx.showToast({ title: '成功', icon: 'success', duration: 2000, success:function(){ console.log('haha') ...
- PHP----composer安装和TP5验证码类
妈的,想用TP5做个项目,用到登录验证码了,结果煞笔TP5不内置了,需要用Composer,用吧,来下载 1.安装Composer 1.1 更新 sudo apt-get update 1.2 安装w ...
- Mysql基础2-数据定义语言DDL
主要: 数据库操作语句 数据表操作语句 视图定义语句 数据库表设计原则 DDL: Data Definition Language 数据定义语言 数据库操作语句 创建库 创建数据库: create d ...
- Python进阶-函数默认参数
Python进阶-函数默认参数 写在前面 如非特别说明,下文均基于Python3 一.默认参数 python为了简化函数的调用,提供了默认参数机制: def pow(x, n = 2): r = 1 ...
- docker和docker compose常用操作命令
首先区分一下docker中几个概念 Image:镜像,相当于一个root文件系统,不包含任何动态数据 Container:容器,镜像运行时的实体,实质是进程,容器进程运行于属于自己的独立的命名空间 d ...
- Java学习笔记九:Java的循环跳转语句
Java的循环跳转语句 一:Java循环跳转语句之break: 生活中,我们经常会因为某些原因中断既定的任务安排.如在参加 10000 米长跑时,才跑了 500 米就由于体力不支,需要退出比赛.在 J ...
- Leecode刷题之旅-C语言/python-26.删除数组中的重复项
/* * @lc app=leetcode.cn id=26 lang=c * * [26] 删除排序数组中的重复项 * * https://leetcode-cn.com/problems/remo ...
- rhel6.4 根目录扩容
状况:根目录容量不足 解决:扩容根目录 ====================================================== 解决步骤: 1. 将新的磁盘加入服务器 2. 使用 ...
- mysql字符串拼接,存储过程
添加字段: alter table `user_movement_log`Add column GatewayId int not null default 0 AFTER `Regionid` (在 ...