比赛 20101118 评测结果 AAAWWWTTWT
题目名称 情敌 最终得分 30
用户昵称 苏轼 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 11:06:42
显示代码纯文本
program rival(input,output);

var
  a,b,n,m,c,tot,i,j,sum:longint;
  fa:array[1..50]of longint;
  x,t,sup:array[1..50]of longint;
  boo:array[0..50]of boolean;

function go(const mon,time:longint):longint;
  var
    i,tmp,ans:longint;
  begin
    if mon=1 then
      ans:=go(mon+1,b)
    else
      ans:=0;

    for i:=1 to n do
      if boo[fa[i]] and not boo[i] then
        if time>=t[i]*mon then
        begin
          boo[i]:=true;
          tmp:=go(mon,time-t[i]*mon)+x[i];

          if tmp>ans then
            ans:=tmp;
          boo[i]:=false;
        end;

    exit(ans);
  end;

begin
  assign(input,'rival.in');
  reset(input);
  assign(output,'rival.out');
  rewrite(output);

  readln(a,b);
  readln(n,m);
  for i:=1 to n do
  begin
    readln(x[i],t[i]);
    sum:=sum+x[i];
  end;

  for i:=1 to m do
  begin
    read(c,tot);
    sup[i]:=c;

    for j:=1 to tot do
    begin
      read(a);
      fa[a]:=i;
    end;
  end;

  boo[0]:=true;
  writeln(sum-go(1,a));

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