题目大意:
n个物品,物品有物抗和魔抗还有价值,要求物抗和魔抗都到达规定值,然后价值最小。
n<21 物抗<21 魔抗<79 价值<800;
思路:
二维费用背包,书上的例题
搜索,对一个物品只有选和不选两种状态,时间就是o
(2^21);
程序:
`var
i,j,n,m,x,y,k,min:longint;
a,b,w:array [1..1000] of longint;
procedure dfs(dep,x1,y1,w1:longint);
var
i,j:longint;
begin
if dep>n+1 then exit;
if (x1>=x) and (y1>=y) then
begin
if min>w1 then min:=w1;
exit;
end;
dfs(dep+1,x1,y1,w1);
x1:=x1+a[dep];
y1:=y1+b[dep];
w1:=w1+w[dep];
dfs(dep+1,x1,y1,w1);
x1:=x1-a[dep];
y1:=y1-b[dep];
w1:=w1-w[dep];
end;
begin
assign(input,'equipment.in'); reset(input);
assign(output,'equipment.out'); rewrite(output);
readln(x,y);
readln(n);
min:=maxlongint;
for i:=1 to n do
readln(a[i],b[i],w[i]);
dfs(1,0,0,0);
writeln(min);
close(input); close(output);
end.