Pagini recente » Diferente pentru problema/fft intre reviziile 7 si 6 | Diferente pentru problema/slide intre reviziile 5 si 9 | Diferente pentru blog/square-root-trick intre reviziile 17 si 18
Nu exista diferente intre titluri.
Diferente intre continut:
Let's see how can we use less memory.
We solve the problem once and save every kth row from the best matrix and from the parent matrix.
We can start from the last saved row to n to compute the solution path from the n - 1 line to [n/k] * k line. And then go lower and lower to compute the part of the solution between the ik (i+1)k. Computing part of the path between row ik and row (i+1)k takes k * m space and k * m time. Computing the whole path takes n/k * (k * m) = nm time and km space, keeping every kth row in memory takes [n/k]m. again we minimize memory by using <tex>k = \sqrt n<\tex>
We can start from the last saved row to n to compute the solution path from the n - 1 line to [n/k] * k line. And then go lower and lower to compute the part of the solution between the ik (i+1)k. Computing part of the path between row ik and row (i+1)k takes k * m space and k * m time. Computing the whole path takes n/k * (k * m) = nm time and km space, keeping every kth row in memory takes [n/k]m. again we minimize memory by using k = sqrt n
Caveats
The above problems have better solutions using interval trees or some other clever tricks. The sqrt trick is nice, since it improves the naive solution a lot without much effort.
Additional problems
1. (Josephus problem) n people numbered from 1 to n sit in a circle and play a game. Starting from the first person and every kth person is eliminated. Write an algorithm that prints out the order in which people are eliminated.
Nu exista diferente intre securitate.
Topicul de forum nu a fost schimbat.