送分: 这个函数怎么改为BCB?(100分)

T

tdKno

Unregistered / Unconfirmed
GUEST, unregistred user!
function FindMaxSum(A:IA;Sum:Integer):Integer;
var
MinLeft:Integer;
Used:array of Boolean;
procedure FindLeft(LeftSum,LeftCount:Integer);
var
i,n,s:Integer;
Str:String;
begin
if (A[0]>LeftSum) or Used[0] then
begin
if LeftSum<MinLeft then
begin
MinLeft:=LeftSum;
Str:='';
s:=0;
n:=0;
for i:=0 to High(A)do
if Used then
begin
Str:=Str+IntToStr(A)+' ';
Inc(s,A);
Inc(n);
end;
//
if (LeftSum=0) or (n>=High(A)) then
Abort;
end;
exit;
end;
n:=LeftCount;
while n>=0do

begin
if A[n]>LeftSum then
Dec(n)
else
break;
end;
for i:=ndo
wnto 0do

begin
Used:=true;
FindLeft(LeftSum-A,i-1);
Used:=false;
end;
end;

begin

SetLength(Used,High(A)+1);
FillChar(Used[0],(High(A)+1)*SizeOf(Boolean),0);
MinLeft:=Sum;
try
FindLeft(Sum,High(A));
except
end;
Result:=Sum-MinLeft;
end;
 
没有人出手?
 

Similar threads

I
回复
0
查看
639
import
I
I
回复
0
查看
617
import
I
I
回复
0
查看
714
import
I
I
回复
0
查看
661
import
I
顶部