当前位置:网站首页>Class notes (4) (3) -573. Lecture hall arrangement (Hall)
Class notes (4) (3) -573. Lecture hall arrangement (Hall)
2022-07-24 21:17:00 【xyc20120615】
Catalog :
Description
There is a lecture hall that we need to manage , The speakers set the starting time and ending time of the speech in advance . We want to maximize the use of the lecture hall . We have to accept some reservations and reject others , The goal is to make speakers use the hall the longest . Suppose at some point a speech ends , Another speech can start immediately .
【 Programming tasks 】
1、 Enter the speaker's Application .
2、 Calculate the maximum possible use time of the lecture hall .
3、 Output the result .
Format
Input
Enter the first line as an integer N(N≤5000), Indicates the number of applications .
following n Each line contains two integers p,k(1≤p<k≤30000), Indicates the start time and end time of this application .
Output
The output contains an integer , Indicates the maximum possible use time of the hall .
Samples
input data 1
12
1 2
3 5
0 4
6 8
7 13
4 6
9 10
9 12
11 14
15 19
14 16
18 20
Output data 1
16
Limitation
1s, 1024KiB for each test case.
Hint
The time of each activity here is “ End time - Starting time ”.
Answer key :
It's a disguised examination 0/1 knapsack , Add a structure, get a reorganization function, and then sort .
Program :
#include <bits/stdc++.h>
using namespace std;
int n,dp[30010];// The number of arrays is the maximum end time
struct T{
int b,e,ans;//b It's the start time (begin),e It's the end time (end),ans For the use time of the application
bool operator<(const T &B)const{
return e<B.e||(e==B.e&&b<=B.b);
}
}a[5010];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].b>>a[i].e;
a[i].ans=a[i].e-a[i].b;// Calculate usage time
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)// Traverse n Applications
for(int j=a[n].e;j>=a[i].e;j--)
dp[j]=max(dp[j],dp[a[i].b]+a[i].ans);
cout<<dp[a[n].e];
return 0;
}边栏推荐
- MySQL data recovery
- 250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
- Practical skills!!
- Baidu interview question - judge whether a positive integer is to the power of K of 2
- How to learn automated testing
- [jzof] 04 search in two-dimensional array
- Using skills and design scheme of redis cache (classic collection version)
- Application layer - typical protocol analysis
- Static & dynamic & file address book
- ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
猜你喜欢

Preview and save pictures using uni app

Evolution of network IO model

How to set the allure test report

rogabet note 1.1
![[basic data mining technology] exploratory data analysis](/img/0c/1b73098a589a2af398dd3cd9d62cd7.png)
[basic data mining technology] exploratory data analysis

C synchronous asynchronous callback state machine async await demo

The difference between token and session, this classic interview question deserves a more in-depth answer

Leetcode skimming -- bit by bit record 017

Metauniverse: technological evolution, industrial ecology and big country game

Upgrade appium automation framework to the latest 2.0
随机推荐
Leetcode skimming -- bit by bit record 017
Strong reference, weak reference, soft reference, virtual reference
Summary of yarn Explorer
Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)
Overloaded & lt; for cv:: point;, But VS2010 cannot find it
【MLFP】《Face Presentation Attack with Latex Masks in Multispectral Videos》
Open source demo | release of open source example of arcall applet
What are intelligent investment advisory products?
Mysql database query is so slow. Besides index, what else can it do?
Scientific computing toolkit SciPy image processing
MySQL data recovery
Using skills and design scheme of redis cache (classic collection version)
A simple method -- determine whether the dictionary has changed
ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime
Generate self signed certificate: generate certificate and secret key
How to gracefully realize regular backup of MySQL database (glory Collection Edition)
[basic data mining technology] exploratory data analysis
HSPF (hydraulic simulation program FORTRAN) model
Oracle creates table spaces and views table spaces and usage
Classical review: understanding the "knowledge consistency" of neural networks (ICLR 2020)