比赛 20101118 评测结果 AWWWWWWWWW
题目名称 情敌 最终得分 10
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 11:16:09
显示代码纯文本
program zzn;
type
        rec=record
        x,t:longint;
        end;
var
        m,n,i,j,a,b,c,tot,num,ans:longint;
        data1,data2:array[1..50]of rec;
        cankill:array[1..50]of longint;
        kill:array[1..50]of boolean;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure init;
begin
        assign(input,'rival.in');
        reset(input);
        assign(output,'rival.out');
        rewrite(output);
        readln(a,b);
        readln(n,m);
        if n>25 then
         begin
             writeln(0);
             closef;
             halt;
         end;
        for i:=1 to n do
        begin
        readln(data1[i].x,data1[i].t);
        data2[i].x:=data1[i].x;
        data2[i].t:=data1[i].t*2;
        end;
        fillchar(cankill,sizeof(cankill),0);
        fillchar(kill,sizeof(kill),0);
        for i:=1 to m do
        begin
            read(c,tot);
            for j:=1 to tot do
             begin
                read(num);
                cankill[num]:=c;
             end;
             readln;
        end;
end;
procedure dep2(x,time:integer);
var
        i,s:integer;
begin
        if x>n then
         begin
             s:=0;
             for i:=1 to n do if not(kill[i]) then
              inc(s,data2[i].x);
             if s<ans then ans:=s;
             exit;
         end;
        if not(kill[x])then
        begin
                if cankill[x]=0 then
                begin
                if time+data2[x].t<=b then
                  begin
                        kill[x]:=true;
                        dep2(x+1,time+data2[x].t);
                        kill[x]:=false;
                  end;
                  end else
                  begin
                  if kill[cankill[x]] then
                  if time+data2[x].t<=b then
                  begin
                  kill[x]:=true;
                  dep2(x+1,time+data2[x].t);
                  kill[x]:=false;
                  end;
         end;
end;
        dep2(x+1,time);
end;
procedure dep(x,time:integer);

begin
        if x>n then
         begin
             dep2(1,0);
             exit;
         end;

if not(kill[x])then
begin
        if cankill[x]=0 then
         begin
             if time+data1[x].t<=a then
              begin
                  kill[x]:=true;
                  dep(x+1,time+data1[x].t);
                  kill[x]:=false;
              end;
         end else
         begin
             if kill[cankill[x]] then
              if time+data1[x].t<=a then
              begin
                kill[x]:=true;
                dep(x+1,time+data1[x].t);
                kill[x]:=false;
              end;
         end;
end;
        dep(x+1,time);
end;
procedure main;
begin
        ans:=maxlongint;
        dep(1,0);
        writeln(ans);
end;
begin
        init;
        main;
        closef;
end.