# make string a postfix notation

Imagine x is an operand and * is a binary operator. We say a string of x and * follows Reverse Polish notation if it is a postfix notation.

For example strings xx*, x, and xx*xx** follow Reverse Polish notation.

Given a string of x and *, how many insert, delete, and replace operations are needed to make the string follow the RPN.

For example, xx* need 0 operation to follow RPN since it already follows RPN.
x*x needs two operations to become xx* which follows RPN.
*xx* needs one operation to become xx* which follows RPN.

Your algorithm should work for a string of size up to 100.

# No. 16 – Maximal Length of Incremental Subsequences

Problem: Given an unsorted array, find the max length of subsequence in which the numbers are in incremental order.

For example: If the input array is {7, 2, 3, 1, 5, 8, 9, 6}, a subsequence with the most numbers in incremental order is {2, 3, 5, 8, 9} and the expected output is 5.

# No. 25 – Edit Distance

Problem: Implement a function which gets the edit distance of two input strings. There are three types of edit operations: insertion, deletion and substitution. Edit distance is the minimal number of edit operations to modify a string from one to the other.

For example, the edit distance between “Saturday” and “Sunday” is 3, since the following three edit operations are required to modify one into the other:

1. Saturday → Sturday (deletion of ‘a’)
2. Sturday→ Surday (deletion of ‘t’)
3. Surday → Sunday (substitution of ‘n’ for ‘r’)

There is no way to achieve it with fewer than three operations.

# No. 44 – Dynamic Programming on Stolen Values

Problem: There are n houses built in a line, each of which contains some value in it. A thief is going to steal the maximal value in these houses, but he cannot steal in two adjacent houses because the owner of a stolen house will tell his two neighbors on the left and right side. What is the maximal stolen value?

For example, if there are four houses with values {6, 1, 2, 7}, the maximal stolen value is 13 when the first and fourth houses are stolen.

# 约瑟夫环问题

1, 2, 3, … , k, k+1, k+2, … , n

1, 2, 3, … , k, k+1, … , n-1

k+1, k+2, … , n, 1, 2, … , k-2, k-1

x -> x k+1 -> 1 k+2 -> 2 ... n -> k ... k-2 -> n-2 k-1 -> n-1

 

变换公式是：x = (x-k+n)%n