比赛 20101118 评测结果 AAAAAAAAAA
题目名称 情敌 最终得分 100
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 10:55:12
显示代码纯文本
program rival;
var
  a,b,c,n,m,i,j,k,p:longint;
  tot:int64;
  x,t:array[0..51]of longint;
  fa,a2:array[0..60]of longint;
  tab:array[0..52,0..101,0..101,0..1]of int64;
  s:array[0..60]of boolean;
begin
  assign(input,'rival.in');
  assign(output,'rival.out');
  reset(input);
  rewrite(output);
  readln(a,b);
  readln(n,m);
  for i:=1 to n do
    readln(x[i],t[i]);
  for i:=1 to m do
  begin
    read(c,tot);
    a2[0]:=a2[0]+1;
    a2[a2[0]]:=c;
    s[c]:=true;
    for j:=1 to tot do
    begin
      read(k);
      fa[k]:=c;
      a2[0]:=a2[0]+1;
      a2[a2[0]]:=k;
    end;
  end;
  x[n+1]:=1;
  t[n+1]:=0;
  tot:=0;
  s[n+1]:=true;
  for i:=1 to n do
    tot:=tot+x[i];
  a2[0]:=a2[0]+1;
  a2[a2[0]]:=n+1;
  for i:=1 to n do
    if (not s[i])and(fa[i]=0) then begin
      a2[0]:=a2[0]+1;
      a2[a2[0]]:=i;
      fa[i]:=n+1;
     end;
  for i:=n+1 downto 1 do
    if s[a2[i]] then
      for j:=a downto 0 do
        for k:=b downto 0 do
          for p:=0 to 1 do
          begin
            if tab[i,j,k,p]<tab[i+1,j,k,0] then
              tab[i,j,k,p]:=tab[i+1,j,k,0];
            if (j>=t[a2[i]])and(tab[i,j,k,p]<tab[i+1,j-t[a2[i]],k,1]+x[a2[i]]) then
              tab[i,j,k,p]:=tab[i+1,j-t[a2[i]],k,1]+x[a2[i]];
            if (k>=t[a2[i]]*2)and(tab[i,j,k,p]<tab[i+1,j,k-2*t[a2[i]],1]+x[a2[i]]) then
              tab[i,j,k,p]:=tab[i+1,j,k-2*t[a2[i]],1]+x[a2[i]];
            end
            else
              for j:=a downto 0 do
                for k:=b downto 0 do
                begin
                  tab[i,j,k,0]:=tab[i+1,j,k,0];
                  if tab[i,j,k,1]<tab[i+1,j,k,1] then tab[i,j,k,1]:=tab[i+1,j,k,1];
                  if (j>=t[a2[i]])and(tab[i,j,k,1]<tab[i+1,j-t[a2[i]],k,1]+x[a2[i]]) then
                    tab[i,j,k,1]:=tab[i+1,j-t[a2[i]],k,1]+x[a2[i]];
                  if (k>=2*t[a2[i]])and(tab[i,j,k,1]<tab[i+1,j,k-2*t[a2[i]],1]+x[a2[i]]) then
                    tab[i,j,k,1]:=tab[i+1,j,k-2*t[a2[i]],1]+x[a2[i]];
            end;
            if tab[1,a,b,0]>tab[1,a,b,1] then
              writeln(tot-tab[1,a,b,0]+1) else writeln(tot-tab[1,a,b,1]+1);
  close(input);
  close(output);
end.