vara:array[1..10000]of longint;f:array[1..10000]of boolean;num,n,x,b,i,j:longint;flag:boolean;procedure work(m,time:longint);beginif m=b then begin if time=1 then if f[m-a[m]] then begin f[m-a[m]]:=false; work(m-a[m],time+1); f[m-a[m]]:=true; end;end;beginassign(input,'lift.in');assign(output,'lift.out');reset(input); rewrite(output);fillchar(f,sizeof(f),true);readln(n,x,b);for i:=1 to n do read(a[i]);num:=100000;work(x,0);if flag then writeln(num) else writeln(-1);close(input); close(output);end.
其实这个要用搜索做的。回溯法效率低