Question:
Given an array A[1..N], find the i, j such that for all 1 <= i < j <= N, find the largest A[j] - A[i]
Answer:
For array A[1..N]
let f(n) to be the result value for the first n elements.
let m(n) to be the smallest element of A[1]..A[n].
f(n) = max{ f(n-1), A[n] - m(n-1) }
m(n) = min{ m(n-1), A[n] }
Solve with DP, O(n) time, O(1) space.
Friday, February 29, 2008
Meta key problem on Mac
Just got my Macbook Pro. I'm trying to ssh to my devbox and use emacs there. The meta key is not working. On windows keyboard, the Alt key sends the meta key. Then there is an option for terminal to solve this problem.
Just go to Window settings for Terminal. Choose the keyboard page and enable the option "use option key as meta key".
Just go to Window settings for Terminal. Choose the keyboard page and enable the option "use option key as meta key".
Thursday, February 28, 2008
"screen" on Mac OS X
I use "screen" to keep connections to remote servers. However, the mac machine has a different keyboard than a PC, so backspace and some other keys may not work.
A simple and quick solution is to add the following line to your shell profile of your account on the remote server.
alias screen="TERM=screen screen"
A simple and quick solution is to add the following line to your shell profile of your account on the remote server.
alias screen="TERM=screen screen"
Subscribe to:
Posts (Atom)