This problem was created by professor Ronaldo Garcia from Universidade Federal de Goiás (UFG) and he showed it to me at an event in my university. This problem has a lot of history and he told me he showed it to a lot of math professors and even some people with some computer science background, but there wasn't much progress. I have also asked this here and my question is the same as this question and this question, but my question on the other forum didn't get much attention and the other questions I linked haven't had recent activity since $\approx 10$ years. So here I share the small progress I made in hopes of inspiring someone to try this problem.
To better explain the question, I'll talk about one special case first:
You are in the euclidean plane. You have $n=3$ segments of different lengths (fixed and given) and $n-1=2$ positive different values of angles (also fixed and given) such that their sum does not exceed $\dfrac{\pi}{2}$. You can pick any segment, place it on the plane, and then place another segment (sharing an endpoint) on the plane such that the angle of deviation is one of the two specified angles. And then you put the other segment in a similar way rotated by the remaining angle. You can only rotate anti-clockwise. So here is a picture of a generic arrangement: (the segments $f$, $g$ and $h$ all have different lengths. Also, $\alpha \neq \beta$, $\alpha, \beta > 0$ and $\alpha + \beta < \dfrac{\pi}{2}$). Notice that this $\dfrac{\pi}{2}$ intuitively says that you can't "go back in the x axis".
The question is: given these values of lengths and angles, is there a fixed way of creating an arrangement with them (notice that there are $\dfrac{3! \cdot 2!}{2} = 6$ possible arrangements for this case) such that the distance between the initial point (the origin in the picture) and the final point (point D in the picture) is as big as possible? By fixed arrangement, I mean something like "putting the lengths in decreasing order and the angles in increasing order is always the best strategy".
For this case ($n=3$), the problem is not hard to solve (and to prove): the distance is always maximized when you start with the smallest length, rotate by the biggest angle, place the biggest length, rotate by the remaining angle and put the remaining segment which has intermediary length. Namely, no matter what are the values of the segments and the values of the angles (satisfying the stated conditions), this particular way of placing them always maximizes the distance between the initial and final points (when compared to the $5$ other ways of placing them).
For higher values of $n$, we thought that there would be either a single way of organizing them or few ways to do that. However, that is wrong: I made a c++ program in which the value of $n$ is given as input and it generates several sets of values for the lengths and angles (which satisfy the criteria). For each set of values, it checks all of its possible arrangements and saves the one that maximizes the distance between the initial and final points. And after doing that for all sets of values, it checks the number of different arrangements generated. As expected, it only finds one possible arrangement for $n=3$. But for $n=4$, it was able to find $3$ possible arrangements. In particular, if you define $a_n$ as the number of arrangements for an arbitraty positive integer $n$, I know that
$$a_1=a_2=a_3=1$$ $$a_4\geq3$$ $$a_5\geq6$$ $$a_6\geq14$$ $$a_7\geq29$$
For the cases in which $n \leq 6$, the program tested $10^6$ sets of (valid) values of lengths and angles. This makes me guess that $a_4$ is $3$ and $a_5$ is $6$, but $a_6$ may be higher than $14$. For $n=7$, the program tested $10^5$ sets of values. I haven't tested it for $n=8$, but only to find the best permutation among a particular set of valid values, it took about $40$ seconds, so this discourages me to try thousands of sets of values for this case. User Claude Chaunier made a program in Rust and claims to have gotten the same bounds for $a_n$ up to $n=6$.
So my actual question is: is there a nice way of expressing $a_n$ and/or characterizing the relative orderings of the arrangements of lengths and angles counted by $a_n$?
If it helps, given the angles $\alpha_1$, ..., $\alpha_{n-1}$ and the segment lengths $l_1$, ..., $l_n$ (where $\alpha_i$ is the deviation angle between the segments of lengths $l_i$ and $l_{i+1}$), then it is possible to prove that the square of the distance between the initial and final point is given by:
$$ \sum\limits_{i=1}^n l_i^2 + 2 \cdot \sum\limits_{1 \leq i < j \leq n} l_i l_j \cos \left( \sum\limits_{k=i}^{j-1} \alpha_k \right)$$
In particular, if $n=2$ this equation is simply the typical law of cossines.
EDIT: The naive algorithm (putting the longest segment first, rotate by the smallest angle, put the second longest, rotate by the second smallest angle, etc) never works for $n=3$. And I conjecture that it never works for all $n \geq 3$. And by "never works" I mean that this arrangement is never one of those which are counted by $a_n$. To make this observation and my question itself more concrete, here is an example for $n=3$: as suggested by @Matt F. take $l_0 = 1$, $l_1 = 2$ and $l_2 = 3$ as the lengths of the segments and take $\alpha_0 = \sin^{-1} \left( \dfrac{7}{25} \right)$ and $\alpha_1 = \sin^{-1} \left( \dfrac{4}{5} \right) - \sin^{-1} \left( \dfrac{7}{25} \right)$ (notice that $\alpha_1 > \alpha_0$ and $l_2 > l_1 > l_0$).
According to the naive algorithm, we should place $l_2$ (we go to $(3, 0)$), then rotate by $\alpha_0$, then place $l_1$ (we go to $(4.92, 0.56)$), then rotate by $\alpha_1$ and then place $l_2$ (we go to $(5.52, 1.96)$). With this, the squared distance is $32.32$.
However, as already stated, for $n=3$ it's not hard to prove (you can use the "generalized cosine law" I put above) that for $n=3$ you should always pick the smallest length $l_0$ (you go to $(1, 0)$), rotate by the biggest angle $\alpha_1$, pick the biggest length $l_2$ (you go to $(3.4, 1.8)$), pick the smallest angle $\alpha_0$ and pick the middle length $l_1$ (you go to $(4.6, 3.4)$) (alternatively, you could also say that we start with $l_1$, rotate $\alpha_0$, pick $l_2$, rotate by $\alpha_1$ and place $l_0$ but that's the same thing because of the simmetry of the problem). So the squared distance here is $32.72 > 32.32$. So the naive algorithm doesn't work in this example (and doesn't work in any example for $n=3$ and probably not for any $n \geq 4$).
EDIT 2: Here are the arrangements I found for $3 \leq n \leq 7$ which are counted by $a_n$: link. For example, at $n=3$
a_3 = 1
0 2 1 || 1 0
means that the only solution I found for $n=3$ was putting $l_0$ first, rotating by $\alpha_1$, putting $l_2$, rotating by $\alpha_0$ and putting $l_1$, as expected. (where $l_2 > l_1 > l_0$ and $\alpha_1 > \alpha_0$)
EDIT 3: As commented by user Claude Chaunier, he noticed that the all the arrangements of the $l$'s seem to be unimodal permutations. But it still remains to figure out how the arrangements of the $l$'s relate to the arrangements of the $\alpha$'s.