Friday Free Timetable
Time limit3sMemory limit512 MB
Count the subsets of classes with no Friday meetings, no overlapping classes on the same weekday, and total credits exactly k.
- Level
Medium4 of 10
- Topics
- Bit manipulation, Brute force, Recursion
- Solved
- No attempts yet
Problem
Yun Heon is building his timetable for course registration season. Last semester he took a Friday class, and his friends teased him endlessly for it. This semester he has resolved to keep Friday free no matter what!!
You are given the weekday, start period, and end period of classes available at Korea University. Weekdays run from Monday to Friday and are given as integers 1 to 5. Start period and end period are integers from to . A class is worth credits.
Yun Heon wants to take exactly credits this semester. He wants to know how many timetables leave Friday with no classes.
Two classes that meet on the same weekday and overlap in any period cannot both be taken. For example, a class from period 5 to period 7 on Tuesday and a class from period 7 to period 9 on Tuesday cannot be taken together.
Count the timetables that total exactly credits and have no classes on Friday for Yun Heon.
Input
The first line contains the number of available classes and the number of credits Yun Heon wants, separated by a space.
The next -th line contains the weekday , start period , and end period of class , separated by spaces.
Output
Print the number of timetables that total exactly credits and have no classes on Friday.
Constraints
Hint
A class that meets on Tuesday from period 5 to period 7 is given as 2 5 7.