【题意】
一周有7天每天12节课,有n种课程,每种只需要去上m[i]节课中的一节课就可以了,求最多能上多少门课程
【输入】
多组数据
每组数据第一行n
接下来n行第一个数字为t,之后2t个数字描述这些课分别是哪一天的哪一节
【输出】
对于每组数据,输出一个数表示最多能上多少门课程
最大流
program poj2239; var ans,tot,n,m,i,j,k,t,q,p:longint; yes:array [0..401] of boolean; last,dl,root:array [0..401] of longint; next,point,flow:array [0..30001] of longint; function anti (now:longint):longint;inline; begin if now and 1 = 1 then exit(now+1) else exit(now-1); end; procedure connect (u,v,f:longint);inline; begin inc(tot); point[tot]:=v; flow[tot]:=f; next[tot]:=root[u]; root[u]:=tot; end; function maxflow :longint; begin ans:=0; repeat tot:=0; i:=0; dl[0]:=0; fillchar(yes,sizeof(yes),false); while i<=tot do begin k:=root[dl[i]]; while k<>0 do begin if (flow[k]>0)and(not yes[point[k]]) then begin yes[point[k]]:=true; inc(tot); dl[tot]:=point[k]; last[point[k]]:=k; end; k:=next[k]; end; if yes[400] then break; inc(i); end; if not yes[400] then break; inc(ans); i:=400; while i<>0 do begin dec(flow[last[i]]); inc(flow[anti(last[i])]); i:=point[anti(last[i])]; end; until false; exit(ans); end; begin while not seekeof do begin fillchar(root,sizeof(root),0); tot:=0; read(n); for i:=1 to n do begin connect(0,i,1); connect(i,0,0); read(t); for j:=1 to t do begin read(p,q); connect(i,n+p*12-12+q,1); connect(n+p*12-12+q,i,0); end; end; for p:=1 to 7 do for q:=1 to 12 do begin connect(n+p*12-12+q,400,1); connect(400,n+p*12-12+q,0); end; writeln(maxflow); end; end.