After seeing this title, I finally handed in the ctsc tree DP. The WA result is self-evident.
There are two ways to carefully read the question:
1. Split each course into two points.
(I '--> J)
(I --> J ')
The following is a problem with the largest independent set. You can subtract the number of matching points.
This idea has no practice. If there is something wrong, please point it out.
2. Many people use this method. The bipartite graph has 84 time points on one side and the course on the other side. After the edge is connected, find the maximum match.
View code
1 program pku2239(input,output);
2 var
3 f : array[0..100,0..301] of boolean;
4 lk : array[0..301] of longint;
5 v : array[0..301] of boolean;
6 n : longint;
7 procedure init;
8 var
9 i,j,x,y,z : longint;
10 begin
11 fillchar(f,sizeof(f),false);
12 fillchar(lk,sizeof(lk),0);
13 readln(n);
14 for i:=1 to n do
15 begin
16 read(x);
17 for j:=1 to x do
18 begin
19 read(y,z);
20 f[(y-1)*12+z,i]:=true;
21 end;
22 readln;
23 end;
24 end; { init }
25 function find(now :longint ):boolean;
26 var
27 i : longint;
28 begin
29 for i:=1 to n do
30 if (f[now,i])and(not v[i]) then
31 begin
32 v[i]:=true;
33 if (lk[i]=0)or(find(lk[i])) then
34 begin
35 lk[i]:=now;
36 exit(true);
37 end;
38 end;
39 exit(false);
40 end; { find }
41 function main():longint;
42 var
43 i : longint;
44 begin
45 main:=0;
46 for i:=1 to 12*7 do
47 begin
48 fillchar(v,sizeof(v),false);
49 if find(i) then
50 inc(main);
51 end;
52 end; { main }
53 begin
54 while not eof do
55 begin
56 init;
57 writeln(main);
58 end;
59 end.