NC24158 [USACO 2015 Jan G]Moovie Mooving
题目
题目描述
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).
输入描述
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.
输出描述
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.
示例1
输入
4 100
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0
输出
3
备注
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.
题解
知识点:状压dp,二分。
TSP问题的变种,变化在于每个点都有不同条件以及对应的不同贡献,选择一个作为下一个点时,需要选择这个点的最优解贡献,可以在排序的情况下二分查找。
这道题需要选择一个电影后,查找这个电影合法且最佳播放时间,如果不存在一个合法的就不能选这个点。
时间复杂度 \(O(2^n\sum \log c_i)\)
空间复杂度 \(O(2^n + \sum c_i)\)
代码
#include <bits/stdc++.h>
using namespace std;
int d[27], c[27][1007];
int dp[(1 << 20) + 7];
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N, L;
cin >> N >> L;
for (int i = 1;i <= N;i++) {
cin >> d[i];
cin >> c[i][0];
for (int j = 1;j <= c[i][0];j++)
cin >> c[i][j];
}
memset(dp, -0x3f, sizeof(dp));
dp[0] = 0;
int ans = ~(1 << 31);
for (int i = 0;i < (1 << N);i++) {
for (int j = 1;j <= N;j++) {
if (!(i & (1 << (j - 1))) || dp[i ^ (1 << (j - 1))] < 0) continue;///实际上不用判断上一个状态存不存在,因为如果不存在导致这一次从0开始加了,那一定存在一种更小的方案,所以也不影响答案
int k = upper_bound(c[j] + 1, c[j] + c[j][0] + 1, dp[i ^ (1 << (j - 1))]) - c[j] - 1;///持续时间固定,找到开始时间最接近的
if (k) dp[i] = max(dp[i], c[j][k] + d[j]);///存在k直接选,则开始时间+持续时间和已有最大值比较,如果小了,选了也不影响最终答案
}
if (dp[i] >= L) ans = min(ans, __builtin_popcount(i));
}
cout << (ans > N ? -1 : ans) << '\n';
return 0;
}
NC24158 [USACO 2015 Jan G]Moovie Mooving的更多相关文章
- B【USACO 2015 Jan Gold】牧草鉴赏家
时间限制 : 10000 MS 空间限制 : 65536 KB 问题描述 约翰有n块草场,编号1到n,这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝 ...
- 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 ...
- Usaco 2019 Jan Platinum
Usaco 2019 Jan Platinum 要不是昨天老师给我们考了这套题,我都不知道usaco还有铂金这么一级. 插播一则新闻:杨神坚持认为铂金比黄金简单,原因竟是:铜 汞 银 铂 金(金属活动 ...
- 【题解】晋升者计数 Promotion Counting [USACO 17 JAN] [P3605]
[题解]晋升者计数 Promotion Counting [USACO 17 JAN] [P3605] 奶牛们又一次试图创建一家创业公司,还是没有从过去的经验中吸取教训.!牛是可怕的管理者! [题目描 ...
- USACO翻译:USACO 2012 JAN三题(2)
USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...
- USACO翻译:USACO 2012 JAN三题(1)
USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...
- USACO翻译:USACO 2013 JAN三题(1)
USACO 2013 JAN 一.题目概览 中文题目名称 镜子 栅栏油漆 奶牛排队 英文题目名称 mirrors paint lineup 可执行文件名 mirrors paint lineup 输入 ...
- USACO翻译:USACO 2014 JAN三题(2)
USACO 2014 JAN 一.题目概览 中文题目名称 队伍平衡 滑雪录像 滑雪场建设 英文题目名称 bteams recording skicourse 可执行文件名 bteams recordi ...
- USACO翻译:USACO 2014 JAN三题(1)
USACO 2014 JAN 一.题目概览 中文题目名称 滑雪场设计 滑雪降速 滑雪场评级 英文题目名称 skidesign slowdown skilevel 可执行文件名 skidesign sl ...
随机推荐
- 【收集】C & C++
序 链接 备注 1 C语言0长度数组(可变数组/柔性数组)详解_CHENG Jian的博客-CSDN博客_0数组 2 C 语言参考 | Microsoft Learn 3 C++ 语言参考 | ...
- JMS微服务开发示例(九)相同的微服务,按用户所在城市来分配微服务器
虽然,默认情况下,多个相同的微服务,网关是自动根据微服务的压力情况,把用户请求分配到压力较轻的微服务器上. 但是,在某些业务情景下,我们可能希望人为去控制微服务的请求分配. 举个例子,我在北京.上海. ...
- SpringBoot3集成Zookeeper
标签:Zookeeper3.8 ,Curator5.5: 一.简介 ZooKeeper是一个集中的服务,用于维护配置信息.命名.提供分布式同步.提供组服务.分布式应用程序以某种形式使用所有这些类型的服 ...
- springboot入参下划线转驼峰出参驼峰转下划线
springboot入参出参下划线转驼峰 前言 因为历史原因前端入参和出参都为下划线,下划线对有亿点强迫症的我来说是不可接受的.因此就有了下面这篇. 本篇基于之前的一篇springboot封装统一返回 ...
- Nginx IP地址较少时如何合理分配后端服务资源
Nginx IP地址较少时如何合理分配后端服务资源 背景 客户系统很多时候会通过网闸或者是VPN登录到产品内 此时的IP地址一般是相同的. 这种情况下较难实现根据ip地址使用ip_hash的方式将压力 ...
- [转帖]10.2 Data Collector与MDW
10.2 Data Collector与MDW Data Collection功能是SQL SERVER 2005版本提供的数据库监控报表的功能,通过定时地对数据库的语句运行情况,服务器各种资源的监控 ...
- [转帖]sql_exporter的使用
https://www.jianshu.com/p/df4b7a7cfc0d 一.背景 有些时候,我们想看每天系统的登录人数.或者系统中订单的数据,比如:成功的订单.异常的订单等等.这些数据都在我们的 ...
- [转帖]CPU Turbo&Cstate&Pstate简介
https://www.jianshu.com/p/eaefd1eb0ac6 测试环境 CPU 1 Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz 16 3130 3 ...
- [转帖]centos7 firewall-cmd主机之间端口转发
目录 1. firewalld 1.1 firewalld守护进程 1.2 控制端口/服务 1.3 伪装IP 1.4 端口转发 2. 案例 2.1 配置ServerA 2.2 安装nginx测试 (可 ...
- gcore的学习
gcore的学习-解决jmap无法生成dump文件的一种方法 背景 周末在跆拳道馆看孩子练跆拳道. 开着笔记本翻到了 扣钉日记 公众号里面的讲解 想着自己也遇到过无法保存dump文件的情况. 所以想学 ...