CodePudding user response:
Looks a bit difficult, don't only exhaustive a range? You should ask in your math BBS have good algorithm, the specific implementation with what language is not a big problem,CodePudding user response:
Well, thank you, I ask mathematical BBS to consultCodePudding user response:
According to the conditions, only general exhaustion, such, was a long search, especially N> ? And even more so...CodePudding user response:
If only the sequence of any set of meet the conditions, and no additional requirements (e.g., does not require the maximum or minimum sequence, etc.), should be able to programming implementation, here are ideas, welcome to clap brick,For sequence W [I]={w1, w2,... , wN}, make di=wi - w1,
Shall constitute a poor item column D [I]={d1, d2,... , dN}, (here d1=0)
Now we write the original problem with w1 and di again, be:
For the positive number N, find positive integer W1 and integer sequence 0=d1 & lt; D2 & lt; D3 & lt; .
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
W1 NA, 2 + 2 d1 - w1 - d2, w1 + 2 d1 - w1 - d3, w1 + 2 d1 - w1 - d4,... W1, 2 + 2 d1 - w1 - dN
W1 2 + 2 - w1 - d1, d2, NA + 2, 2 w1 d2 - w1 - d3, w1 + 2 d2 - w1 - d4,... W1, 2 + 2 d2 - w1 - dN
W1 2 + 2 d3 - w1 - d1, 2 w1 + 2 d3 - w1 - d2, NA, w1 + 2 d3 - w1 - d4,... W1, 2 + 2 d3 - w1 - dN
W1 + 2 d4 - w1 - d1, 2 + 2, 2 w1 d4 - w1 - d2, w1 2 + 2 - d3, d4 - w1, NA,... W1, 2 + 2 d4 - w1 - dN
.
W1 2 + 2 dn - w1 - d1, 2 w1 + 2 dn - w1 - d2, w1 2 + 2 dn - w1 - d3, w1 + 2 dn - w1 - d4,... , NA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
There is no overlap between elements,
In addition, according to the wN<1.5 w1, w1 + dN<1.5 w1, namely dN<0.5 w1 or w1 & gt; 2 dn,
Now all the w1 minus from above (anyway, requires only a dN, give a & gt; 2 dn value do w1 can satisfy the conditions)
Topic deformation for
For the positive integer N, find an integer sequence 0=d1 & lt; D2 & lt; D3 & lt; .
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
NA, 2 d1, d2, 2 d1, d3, 2 d1 - d4,... , 2 d1 - dN
2 - d1, d2, NA 2 d2, d3, 2 d2 - d4,... , 2 d2 - dN
D3 - d1, 2 d3 - d2, NA, 2 d3 - d4,... , 2 d3 - dN
D4 - d1, 2 d4 - d2 and d4-2 d3, NA,... D4, 2 - dN
.
2 dn - d1, 2 dn - d2, 2 dn - d3, 2 dn - d4,... , NA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
There is no the same element,
That is to say,
For array {d1, d2, d3,... Any 2 dN}, di - DJ can't appear in the original array
This can draw form to find out a set of solutions of these
D, d * 2
0, 0
1, 2
Because 3, 6 (2, 2-2=0 has appeared in the d, can for the 3 for 2-3=1 is not in d)
4, 8 (6-4=2 is not in d, 0 to 4, 2-4 is not in d)
9, 18 (6-5=1, 6-6=0, 8 to 7=1, 8-8=0 are in d, so take 9)
10, 20 (18 to 10=8 is not in d)
18-11, 12, 24 (=7 in d, 18-12=6, 20=8-12 are not in d)
.
DN is derived at last, after another w1=dN * 2 + 1 can be deduced a set of solution of W series,
This way of thinking, can be implemented through two heavy cycle and time complexity is O (N ^ 3) almost, space needs two arrays (1 d, an d * 2, if stored stress can also use an array), space complexity is O (N),
Type
TIntArray=array of Integer;
//check been a value charges in array d
The function isValidValue (value: Integer; D, d2: an array of Integer; MaxIndex: Integer) : Boolean;
Var
I, j: Integer;
V: Integer;
The begin
Result:=true;
For I:=maxIndex downto 0 do
The begin
If d2 [I]exit;
V: d2=[I] - value;
For j:=0 to maxIndex do
The begin
If d [j]=v then
The begin
Result:=false;
exit;
The end;
The end;
The end;
end;
//get the sequence of w
The function getSequence (N: Integer) : TIntArray;
Var
D, d2: an array of Integer;
W1: Integer;
I: Integer;
The begin
SetLength (d, N);
SetLength (d2, N);
D [0] :=0;
D2 [0] : [0]=d * 2;
For I=1 to N - 1 do
The begin
D: [I]] [I - 1 + 1=d;
[I] while not isValidValue (d, d, d2, I - 1) do
The begin
[I] inc (d);
end;
D2: [I] [I] * 2=d;
The end;
SetLength (Result, N);
W1: d2=[N - 1) + 1;
Do the for I:=0 to N - 1
The begin
Result: [I]=w1 + d [I];
The end;
SetLength (d, 0);
SetLength (d2, 0);
The end;
CodePudding user response:
CodePudding user response:
By the way, use the ideas above, can be easily proved that for any N> 1, save at least 1 set of eligible d sequence, therefore there are an infinite number of solutions,Proof for the method of mathematical induction: assuming that when N=k is eligible d={0, d1, d2,... , dk}, then when the N=k + 1, the sequence {0, d1, d2,... , dk, dk * 2 + 1) must satisfy the conditions - because it is clear that the dk * 2 + 1 - ds (s<=k) must be greater than the dk, and any other elements of the ds * 2 necessarily & lt; Dk * 2 + 1 is therefore unlikely to repeat,
According to this idea, if you don't mind Numbers becomes too large, it directly to d=d [k] [k - 1) * 2 + 1 can be in O (N) time sequence,