[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数降序刷 ---------------------------- ...
随机推荐
- 浅谈C#实现Web代理服务器的几大步骤
代理服务程序是一种广泛使用的网络应用程序.代理程序的种类非常多,根据协议不同可以分成HTTP代理服务程序.FTP代理服务程序等,而运行代理服务程序的服务器也就相应称为HTTP代理服务器和FTP代理服务 ...
- ThinkPHP创建应用
新建一个文件 引入ThinkPHP文件
- 洛谷 U45568 赌神:决斗
题目描述 \mathcal{tomoo}tomoo决定与\mathcal{CYJian}CYJian进行决斗! 已知\mathcal{tomoo}tomoo有\mathcal{N}N张扑克牌,每张扑克 ...
- MongoDB在单机上搭建分片副本集群(windows),版本二
配置可以参考前面一篇 https://www.cnblogs.com/a-horse-mosaic/p/9284010.html 副本集是一组服务器,其中有一个主服务器(primary),用于处理客户 ...
- Leecode刷题之旅-C语言/python-136只出现一次的数字
/* * @lc app=leetcode.cn id=136 lang=c * * [136] 只出现一次的数字 * * https://leetcode-cn.com/problems/singl ...
- 谭浩强C语言第四版第九章课后习题7--9题(建立,输出,删除,插入链表处理)
#include<stdio.h> #include<stdlib.h> #define N sizeof(link) typedef struct stu { struct ...
- node解析post表单信息
一共有4种解析方式 urlencoded.json.text .raw 发起请求的form表单中可以设置三种数据编码方式 application/x-www-form-urlencoded.multi ...
- 设置socket接收和发送超时的一种方式
Linux环境设置Socket接收和发送超时: 须如下定义:struct timeval timeout = {3,0}; //设置发送超时setsockopt(socket,SOL_SOCKET, ...
- 【题解搬运】PAT_A1020 树的遍历
题目 Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder an ...
- java 生成简单word(利用Itext工具),生成简单Excel,以及下载笔记
1.java 生成简单word(包含图片表格) pom中加入itext 相关依赖 <dependency> <groupId>com.lowagie</groupId&g ...