Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Scheduling Classes Andy studies at the University of California is very studious. He wants to take as many subjects as possible without any class overlap.

Scheduling Classes

Andy studies at the University of California is very studious. He wants to take as many subjects as possible without any class overlap. The University doesnt impose any restriction on the number of classes taken during the semester.

He really doesnt care about what subject he takes; he likes them all! However, he wants to maximize the number of subjects he can take.

Input Format

The first line of input consists of an integer t. This is the number of days.

  • For each day, the first line contains an integer n which gives the number of subjects offered on that day.
  • Then next n lines follow containing the subject name (which is a string) followed by the start and end time for that subject in 24-hour format: hh: mm

For eg: Maths 10:00 11:00

Note: The timings are given in 24-hour format and the subject names do not have spaces between them.

Output Format

The output should contain t lines and each line has a number representing the maximum number of classes Andy can choose.

Constraints

* 1 <= t <= 5000 * 2 <= n <= 100 * start time of a class < end time of class 

Sample Input

2 4 Maths 16:00 18:00 ComputerScience 12:00 13:00 Physics 12:30 14:00 Chemistry 14:00 16:30 5 Geography 14:00 16:00 History 12:00 14:30 Arts 14:00 16:30 Literature 12:30 13:30 German 13:30 15:00

Sample Output

2 2

Explanation

  • For the 1st day, ComputerScience starts the earliest and ends the earliest, so we take it first. After that, we cannot take Physics because it starts before ComputerScience is over. So we will take the next class, that is, Chemistry. But after Chemistry we cannot take Maths as Maths class starts before Chemistry class ends. So we can schedule a maximum of 2 classes for the first day.
  • Similarly, we schedule for the second day.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

Explain how a physical inventory is taken. LO.1

Answered: 1 week ago

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago