比赛 NOIP水题争霸赛 评测结果 WWWWWWWWWW
题目名称 博士的密码 最终得分 0
用户昵称 AHOI_Captain 运行时间 1.011 s
代码语言 Pascal 内存使用 0.13 MiB
提交时间 2018-02-11 21:29:33
显示代码纯文本
Program Captain;
Var a:array[0..41]of longint;
n,Key,i,x,Ans:longint;
procedure kp(l,r:longint);
var
i,j,mid:longint;
begin
    if l>=r then exit;
    i:=l;j:=r;mid:=a[(l+r) div 2];
    repeat
         while a[i]<mid do inc(i);
         while a[j]>mid do dec(j);
         if i<=j then
         begin
             a[0]:=a[i];a[i]:=a[j];a[j]:=a[0];
             inc(i);dec(j);
         end;
    until i>j;
    kp(l,j);
    kp(i,r)
end;
Procedure Jia(tot,x:longint);
Var i:longint;
Begin
	Inc(tot,a[x]);
	If tot>key then exit;
	If tot=key then begin 
		inc(ans);Exit;
	End;
	For i:=x+1 to n do (jia(tot,i));
	If x=n then exit;
End;
Begin
Assign(input,'password1.in');Reset(input);
Assign(output,'password1.out');Rewrite(output);
	Readln(n,key);i:=0;
	While n>0 do begin
		Dec(n);Read(x);
		If x=key then begin
			inc(ans);
			Continue;
		End else 
		If (x=0) or (x>key) then continue
			else begin
				Inc(i);
				a[i]:=x;
			End;
	End;n:=i;
	kp(1,n);
	For i:=1 to n do jia(0,i);
	Writeln(ans);
Close(input);Close(output);
End.