Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function search(n:integer):boolean;
- var
- k,min,max:integer;
- begin
- For k:=n to length(a)-1 do
- begin
- summ:=summ+a[k];
- temp1:=temp1+inttostr(a[k])+',';
- score:=score+1;
- If (score>len) and (summ>=0) then
- begin
- While summ>=a2[i-1] do
- begin
- setlength(a2,length(a2)+1);
- a2[i]:=2*a2[i-1]+a2[i-2];
- i:=i+1;
- end;
- flag:=false;
- Min:=0;
- max:=length(a2)-1;
- While (flag=false) and (min<max) do
- begin
- If summ>a2[min+((max-min) div 2)] then
- Min:=(min+((max-min) div 2))+1
- else
- If summ=a2[min+((max-min) div 2)] then
- begin
- sum:=summ;
- flag:=true;
- out:=temp1;
- len:=score;
- end
- else
- Max:=(min+((max-min) div 2))-1;
- end;
- end;
- If k<long then
- search(k+1);
- score:=score-1;
- summ:=summ-a[k];
- setlength(temp1,length(temp1)-(length(inttostr(a[k]))+1));
- end;
- Result:=true;
- end;
- //
- procedure TForm1.MenuItem10Click(Sender: TObject); //
- begin
- try
- setlength(a2,2);
- i:=2;
- temp1:='';
- len:=1;
- a2[0]:=1;
- a2[1]:=2;
- memo1.Lines.Clear;
- search(0);
- setlength(out,length(out)-1);
- If len>1 then
- begin
- memo1.lines.add(' ( '+out+') '+' из '+inttostr(len)+' элиментов дает сумму '+inttostr(sum)+' равную одному из элиментов последовательности :');
- out:='{';
- For i:=0 to length(A2)-1 do
- out:=out+inttostr(A2[i])+',';
- out[length(out)]:='}';
- memo1.Lines.Add(out);
- end
- else
- memo1.Lines.Add('Нет совподений');
- except
- showmessage('ERROR#bt18');
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement