Given a sequence of integers, a1, a2,..., an , we define its sign matrix S such that, for 1ijn , Sij = `` + " if ai +...+ aj > 0 ; Sij = `` - " if ai +...+ aj < 0 ; and Sij = ``0"
For example, if (a1, a2, a3, a4) = (- 1, 5, - 4, 2) , then its sign matrix S is a 4×4
| 1 | 2 | 3 | 4 |
1 | - | + | 0 | + |
2 | | + | + | + |
3 | | | - | - |
4 | | | | + |
We say that the sequence (-1, 5, -4, 2) generates the sign matrix. A sign matrix is valid
Given a sequence of integers, it is easy to compute its sign matrix. This problem is about the opposite direction: Given a valid sign matrix, find a sequence of integers that generates the sign matrix. Note that two or more different sequences of integers can generate the same sign matrix.
Write a program that, given a valid
Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases Tis given in the first line of the input. Each test case consists of two lines. The first line contains an integer n (1n10) , where n is the length of a sequence of integers. The second line contains a string of n(n + 1)/2 characters such that the first n characters correspond to the first row of the sign matrix, the next n - 1 characters to the second row, ... , and the last character to the n
Output
Your program is to write to standard output. For each test case, output exactly one line containing a sequence of n
Sample Input
3 4 -+0++++--+ 2 +++ 5 ++0+-+-+--+-+--
Sample Output
思路:设f[i]=ans[0]+..+ans[i],那么上述的i行j列+,-,0关系就表示为f[j]>f[i-1],f[j]<f[i-1],f[j]==f[i-1];
来个拓扑排序,就好了,其中0比较讨厌,那就不管它,只要再拓扑排序时,将没有入度的点都置成一样的值,就一定满足了相等的情况。