比赛 |
20101118 |
评测结果 |
AWWWAWWWWW |
题目名称 |
情敌 |
最终得分 |
20 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-18 11:17:12 |
显示代码纯文本
{情敌
Author: yangbohua
Time: 2010-11-18}
program rival;
var
w,t:array[0..51] of longint;
f:array[0..205] of int64;
p:array[0..5,0..51] of longint;
tot:array[0..5] of longint;
b:array[0..51] of boolean;
n,m,i,j,t1,t2:longint;
ans,ww,sum:int64;
procedure dfs(step:longint);
var
i,j:longint;
begin
if step=m+1 then
begin
fillchar(f,sizeof(f),0);
for i:=1 to n do
if b[i] then
for j:=t1+t2 downto t[i] do
begin
if j<=t1 then
begin
if f[j-t[i]]+w[i]>f[j]
then f[j]:=f[j-t[i]]+w[i];
end
else
begin
if j-t[i]-t[i]>=t1 then
if f[j-t[i]-t[i]]+w[i]>f[j]
then f[j]:=f[j-t[i]-t[i]]+w[i]
end;
end;
if f[t1+t2]+ww>ans
then ans:=f[t1+t2]+ww;
end
else
begin
if (b[p[step,0]]) and (t1>=t[p[step,0]]) then
begin
t1:=t1-t[p[step,0]];
ww:=ww+w[p[step,0]];
dfs(step+1);
t1:=t1+t[p[step,0]];
ww:=ww-w[p[step,0]];
end;
if b[p[step,0]] then
begin
b[p[step,0]]:=false;
for i:=1 to tot[step] do
b[p[step,i]]:=false;
dfs(step+1);
for i:=1 to tot[step] do
b[p[step,i]]:=true;
b[p[step,0]]:=true;
end
else
begin
for i:=1 to tot[step] do
b[p[step,i]]:=false;
dfs(step+1);
for i:=1 to tot[step] do
b[p[step,i]]:=true;
end;
end;
end;
begin
assign(input,'rival.in');
reset(input);
assign(output,'rival.out');
rewrite(output);
readln(t1,t2);
readln(n,m);
sum:=0;
for i:=1 to n do
begin
readln(w[i],t[i]);
sum:=sum+w[i];
end;
for i:=1 to m do
begin
read(p[i,0],tot[i]);
for j:=1 to tot[i] do
read(p[i,j]);
readln;
end;
fillchar(b,sizeof(b),true);
ans:=0;
ww:=0;
dfs(1);
writeln(sum-ans);
close(input);
close(output);
end.