/*** There are n coins in a line. (Assume n is even). Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins. Would you rather go first or second? Does it matter? Assume that you go first, describe an algorithm to compute the maximum amount of money you can win. eg. int a[] = { 3, 2, 2, 3, 1, 2 } Note: 1. array is unsorted 2. the guaranteed win strategy compute the sum of odd and the sum of even (the index of coin) if even > odd, every round, only picked the even coin otherwise, only picked the odd coin 3. the maximum amount of money you can win (different with 2.) Recursive, consider the way to compute subset sum http://leetcode.com/2011/02/coins-in-line.html ***/ #include <iostream> using namespace std; int maxWin( int * a , int index_x , int index_y , int sum ) { //base cas...
declare a list
ReplyDeletelist = []
declare a dictionary
dic = {}
Regular Expressions in Python
ReplyDeleteAn example regex is r"^(From|To|Cc).*?python-list@python.org"
- the caret ^ matches text at the beginning of a line.
- the part with (From|To|Cc) means that the line has to start with one of the words that are separated by the pipe |
- The .*? means to un-greedily match any number of characters, except the newline \n character. The un-greedy part means to match as few repetitions as possible. The . character means any non-newline character, the * means to repeat 0 or more times, and the ? character makes it un-greedy.