|
|
Let's construct the resulting sequence from N to 1 by keeping merged segments in stack. What is the condition for merging two segments? They are touching by one of the sides (r_1+1=l_2 or r_2+1=l_1). The last part of the solution is trivial (make a tree of merges, ...). Give me plz some tests. Please only good permutation :) 4 1 4 2 3 This test help me) (1, (2,3) * (4)) = (1,4,2,3) Wa 7 again :) 9 3 2 1 7 9 8 4 5 6 ((1)*(2)*(3),(4,5,6)*(7,(8)*(9))) For this input: 3 1 2 3 Is this output correct: (1,(2,3)) Why not? I think that it's correct. As an example of evaluating subexpression, (1, (2 * 3), 4) is shown. However, this is not a valid expression according to the grammar (* can only operate on sequences, not numbers). Which is correct? What do you mean by "..." in formal definition? Is it the same as <expression> ::= <sequence>{*<sequence>} and <sequence> ::= (<sequence element>{,<sequence element>} or smth else? |
|
|