当前位置:网站首页>November 20, 2021: the start and end times of a movie can be listed in a small array
November 20, 2021: the start and end times of a movie can be listed in a small array
2022-06-24 01:05:00 【Fuda scaffold constructor's daily question】
2021-11-20: The start and end times of a movie can be represented by a small array "07:30","12:00", It is known that there is 2000 The movie starts and ends on the same day , This day from 00:00 Start to 23:59 end , Be sure to choose 3 A completely conflict free movie to watch , Returns the maximum viewing time . If you can't choose 3 A completely conflict free movie to watch , return -1. From little red book .
answer 2021-11-20:
1. Sort . Sort by start time ; If the start time is the same , Sort by end time .
2. recursive . Three parameters : minute (<=1440), Number of movies left (<=33), What movie number (<=2000).
Time complexity :10 Of 7 Within the power of .
Spatial complexity : Sort of .
The code to use golang To write . The code is as follows :
package main
import (
"fmt"
"sort"
)
func main() {
movies := [][]int{{10, 17}, {18, 19}, {20, 20}}
ret := maxEnjoy2(movies)
fmt.Println(ret)
}
func maxEnjoy2(movies [][]int) int {
sort.Slice(movies, func(i, j int) bool {
a := movies[i]
b := movies[j]
if a[0] != b[0] {
return a[0] < b[0]
} else {
return a[1] < b[1]
}
})
return process2(movies, 0, 0, 3)
}
func process2(movies [][]int, index int, time int, rest int) int {
if index == len(movies) {
return twoSelectOne(rest == 0, 0, -1)
}
p1 := process2(movies, index+1, time, rest)
next := twoSelectOne(movies[index][0] >= time && rest > 0, process2(movies, index+1, movies[index][1], rest-1), -1)
p2 := twoSelectOne(next != -1, (movies[index][1] - movies[index][0] + next), -1)
return getMax(p1, p2)
}
func twoSelectOne(c bool, a int, b int) int {
if c {
return a
} else {
return b
}
}
func getMax(a int, b int) int {
if a > b {
return a
} else {
return b
}
}The results are as follows :
边栏推荐
- Empty encoded password warning reason
- [CVPR 2020] conference version: a physics based noise formation model for extreme low light raw denoising
- What should I pay attention to in the interview of artificial intelligence technology?
- Cvpr2022 𞓜 thin domain adaptation
- Basic usage of setfacl command
- WinSCP和PuTTY的安装和使用
- Real time computing framework: Flink cluster construction and operation mechanism
- What is memory out of order access?
- 社招面试必不可少——《1000 道互联网大厂 Android工程师面试题》
- 【ICPR 2021】遥感图中的密集小目标检测:Tiny Object Detection in Aerial Images
猜你喜欢

Installation and use of winscp and putty

Social recruitment interview is indispensable -- 1000 interview questions for Android engineers from Internet companies

ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

skywalking 安装部署实践
![[applet] realize the effect of double column commodities](/img/e3/b72955c1ae67ec124520ca46c22773.png)
[applet] realize the effect of double column commodities

Everything I see is the category of my precise positioning! Open source of a new method for saliency map visualization

使用worker报错:Uncaught DOMException: Failed to construct ‘Worker’: Script at***

一次 MySQL 误操作导致的事故,「高可用」都顶不住了!

所见之处都是我精准定位的范畴!显著图可视化新方法开源

Open source model library of flying propeller industry: accelerating the development and application of enterprise AI tasks
随机推荐
【CVPR 2020 Oral】极低光去噪论文:A Physics-based Noise Formation Model for Extreme Low-light Raw Denoising
Everything I see is the category of my precise positioning! Open source of a new method for saliency map visualization
【小程序】实现双列商品效果
【SPRS J P & RS 2022】小目标检测模块:A Normalized Gaussian Wasserstein Distance for Tiny Object Detection
【CVPR 2022】高分辨率小目标检测:Cascaded Sparse Query for Accelerating High-Resolution Smal Object Detection
How to improve program performance
【ICCV Workshop 2021】基于密度图的小目标检测:Coarse-grained Density Map Guided Object Detection in Aerial Images
Data management: business data cleaning and implementation scheme
飞桨产业级开源模型库:加速企业AI任务开发与应用
Apple iphone14 is equipped with Beidou navigation system. What are the advantages of Beidou vs GPS?
What should I pay attention to in the interview of artificial intelligence technology?
Is it safe to open an account for shares of tongdaxin?
Shardingsphere-proxy-5.0.0 implementation of capacity range partition (V)
Efficient integration of heterogeneous single cell transcriptome with scanorama
Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training
What are the two types of digital factories
Perhaps the greatest romance of programmers is to commemorate their dead mother with a software
Real time computing framework: Flink cluster construction and operation mechanism
Shardingsphere-proxy-5.0.0 implementation of capacity range partition (V)
Pure JS implementation determines whether the IP is pinged