Title Link: http://poj.org/problem?id=3735
The first idea is to build two (n+1) * (n+1) matrix A, the diagonal is 1, the other element is initially 0, the other (n+1) is the matrix B, for the element (b i1) ∈b,1<= i <=n (matrix element coordinates in the discussion with 1), Indicates the number of peanuts for the nth Cat, initially 0,b (n+1) 1=1.
For the G I operation, add (a I (n+1)) plus 1. ((AIJ) ∈ A)
For the E-I operation, the line I is fully zeroed.
For the S I j operation, the lines I and J are exchanged.
Thus, the modified matrix A to its M-power, and then multiplied by the matrix B to obtain a (n+1) * * of the Matrix , line I (1<= i <=n) indicates the number of the last peanut of the nth cat.
For the problem-like column, the calculation is as follows
Think carefully, the above matrix can be simplified, redefine (n+1) * (n+1) of the moment matrix A, diagonal is 1, for (a i1) ∈a,1<= i <=n the number of peanuts for the nth cat, initially 0.
For the G I operation, add (a I 1) plus 1.
For the E-I operation, the line I is fully zeroed.
For the S I j operation, the lines I and J are exchanged.
This method is equivalent to the previous one, the M power to A,(a i1) ∈am,1<= i <=n the number of peanuts for the nth cat.
POJ 3735 Training Little Cats