比赛 20101118 评测结果 C
题目名称 情敌 最终得分 0
用户昵称 1102 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 11:25:48
显示代码纯文本
program xxxxx;
var a,b,n,m,w,x,i,j,k,c,tot:longint;
    flag:array[0..202,0..50,0..50] of boolean;
    f:array[0..202,0..50] of longint;
    s:array[1..50,0..3] of longint;

function max(a1,a2,a3:longint):longint;
var a4:longint;
begin
  a4:=0;
  if a1>a4 then
    a4:=a1;
  if a2>a4 then
    a4:=a2;
  if a3>a4 then
    a4:=a3;
  max:=a4;
end;



begin
  assign(input,'rival.in');
  reset(input);
  assign(output,'rival.out');
  rewrite(output);
  readln(a,b);
  readln(n,m);
  for i:=1 to a+(b div 2) do
    for j:=1 to n do
      for k:=1 to n do
        flag[i,j,k]:=false;
  w:=0;
  for i:=1 to n do
    begin
      s[i,0]:=0;
      s[i,3]:=0;
      readln(s[i,1],s[i,2]);
      w:=w+s[i,1];
    end;
  for i:=1 to m do
    begin
      read(c,tot);
      s[c,0]:=tot;
      for j:=1 to tot do
        begin
          read(x);
          s[x,3]:=c;
        end;
    end;
  for i:=1 to a+(b div 2) do
    begin
      if i=a+1 then
        for k:=1 to n do
          begin
            f[i,k]:=f[i-1,k];
            flag[i,k,k]:=flag[i-1,k,k];
          end;
      for j:=1 to n do
        begin

          if (s[j,2]<=a)or(s[j,2]<=i-a) then
            if ((i>a)and(i-a-s[j,2]>=0))or((i<=a)and(i-s[j,2]>=0)) then
            if (s[j,0]<>0)or((s[j,3]<>0)and(flag[i-s[j,2],j-1,s[j,3]]))or(s[j,3]=0) then
              begin
                f[i,j]:=max(f[i,j-1],f[i-s[j,2],j-1]+s[j,1],f[i,j]);
                if (s[j,0]<>0)and(f[i,j]=f[i-s[j,2],j-1]+s[j,1]) then
                  flag[i,j,j]:=true;
              end;
          f[i,j]:=max(f[i,j],f[i,j-1],0);
        end;
    end;
  x:=0;
  for i:=1 to a+(b div 2) do
    for j:=1 to n do
      if f[i,j]>x then
        x:=f[i,j];
  write(w-x);


  close(input);
  close(output);
end.
    end;