从数组中取出任意个数,求和为指定值的解 var TestArr:TArray<integer>; procedure CalSum(Arr:TArray<Integer>;Res:Integer); var i,j,sum:Integer; temp:string; begin for i:= 1 to (1 shl Length(Arr))-1 do begin sum:=0; temp:=''; for j:= 0 to Length(Arr)-1 do begin if (i and (1 shl j))<>0 then begin sum:=sum+Arr[j]; temp:=temp+Arr[j].ToString; end; end; if sum=Res then begin Writeln(temp); end; end; end; begin TestArr:=[1,2,3,4,5,6,7,8,9]; CalSum(TestArr,10); Readln; end.
Excel解决方案
Excel规划求解求哪几个数字之和等于一个固定值 标签:Arr,固定值,end,temp,sum,个数,begin From: https://www.cnblogs.com/tulater/p/17585176.html