给出N(5<=N<=14)个课程的起始时间(08:00 ~ 19:00)
时间格式为 HHs MMs HHe MMe,8<=HH<=18, MM的范围: 0, 10, 20, 30, 40, 50
AB两名学生来选,每个学生不能选择时间有冲突的课程
求最后两名学生一共最多能选择多少分钟的课程(每个课程只计算一次)
输入:
用例数T
N
N个课程的起始时间和终止时间
输出:最多能选择多少分钟的课程
5
5
8 0 14 0
9 0 12 0
13 0 18 0
10 0 17 0
10 30 13 30
6
8 0 18 10
13 10 15 20
10 50 13 30
13 20 18 10
12 0 12 50
12 0 15 30
8
10 40 12 20
9 10 15 10
11 0 16 30
11 50 15 50
8 30 13 50
15 0 18 10
9 30 10 10
13 10 18 30
10
10 50 13 50
9 40 12 0
8 20 15 10
8 30 10 20
11 40 13 20
8 20 13 50
14 20 18 10
15 0 16 40
8 0 16 50
10 0 11 10
14
10 40 15 50
9 40 10 0
12 40 16 10
12 40 13 0
12 20 17 40
11 40 17 30
9 0 12 0
16 10 17 30
17 0 18 40
8 40 12 40
8 20 14 30
12 40 18 40
15 0 16 20
9 40 10 10
#1 900
#2 950
#3 970
#4 1090
#5 1150
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int T, N, classStart[14], classEnd[14], total10Mins;
bool flagA[66], flagB[66];
void dfs(int current, int countOf10Mins){
if (current == N){
if (total10Mins < countOf10Mins){
total10Mins = countOf10Mins;
}
return;
}
bool isFreeA = true, isFreeB = true;
for (int i = classStart[current]; i < classEnd[current]; i++){
if (flagA[i])
isFreeA = false;
if (flagB[i])
isFreeB = false;
}
if (isFreeA){
for (int i = classStart[current]; i < classEnd[current]; i++)
flagA[i] = true;
dfs(current + 1, countOf10Mins + classEnd[current] - classStart[current]);
for (int i = classStart[current]; i < classEnd[current]; i++)
flagA[i] = false;
}
if (isFreeB){
for (int i = classStart[current]; i < classEnd[current]; i++)
flagB[i] = true;
dfs(current + 1, countOf10Mins + classEnd[current] - classStart[current]);
for (int i = classStart[current]; i < classEnd[current]; i++)
flagB[i] = false;
}
dfs(current + 1, countOf10Mins);
}
int main(int argc, char** argv) {
freopen("sample_input.txt", "r", stdin);
setbuf(stdout, NULL);
scanf("%d", &T);
for (int test_case = 1; test_case <= T; ++test_case){
scanf("%d", &N);
for (int i = 0; i < N; i++){
int startHH, startMM, endHH, endMM;
scanf("%d%d%d%d", &startHH, &startMM, &endHH, &endMM);
classStart[i] = (startHH - 8) * 6 + startMM / 10;
classEnd[i] = (endHH - 8) * 6 + endMM / 10;
}
for (int i = 0; i < 66; i++){
flagA[i] = flagB[i] = false;
}
total10Mins = -1;
dfs(0, 0);
printf("#%d %d\n", test_case, total10Mins * 10);
}
return 0;
}