You are viewing a single comment's thread. Return to all comments →
This can be also solved using transtion matrix and approach similar to fibonacci series etc. problems. Transition matrix:
(0 1 0 2 1 0) - i^2
(0 0 0 1 0 0) - i-1
(0 0 0 1 1 0) - i
(0 0 0 0 1 0) - const 1
(0 1 0 2 1 1) - Sum(1 to i inclusive)
Initial vector for i=1: (1, 0, 1, 1, 1)
Then use efficient exponentitation to find relevant matrices and multiple. O(log n)
Seems like cookies are disabled on this browser, please enable them to open this website
Little Ashish's Huge Donation
You are viewing a single comment's thread. Return to all comments →
This can be also solved using transtion matrix and approach similar to fibonacci series etc. problems. Transition matrix:
(0 1 0 2 1 0) - i^2
(0 0 0 1 0 0) - i-1
(0 0 0 1 1 0) - i
(0 0 0 0 1 0) - const 1
(0 1 0 2 1 1) - Sum(1 to i inclusive)
Initial vector for i=1: (1, 0, 1, 1, 1)
Then use efficient exponentitation to find relevant matrices and multiple. O(log n)