题目地址:http://codevs.cn/problem/1005/
分析:
搜索
代码:
var
f:array [0..9,0..11] of longint;
a,x:array [0..11] of longint;
i,j,m,n,l:longint;
procedure work(i:longint);
var
c,k,j:longint;
begin
for j:=0 to a[i] do
begin
for k:=1 to m do
x[k]:=x[k]+f[i,k]*j;
if i<n then work(i+1) else
begin
for k:=2 to m do
if x[k]=x[k-1] then
c:=1 else
begin
c:=0;
break;
end;
if (c=1) and (x[1]*m<l) and (x[1]>0) then l:=x[1]*m;
end;
for k:=1 to m do
x[k]:=x[k]-f[i,k]*j;
end;
end;
begin
l:=1001;
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do
read(f[i,j]);
readln;
end;
for i:=1 to n do
read(a[i]);
work(1);
if l<=1000 then writeln(l) else writeln('alternative!');
end.