dynamic-programming

Number of combinations for 4xN domino bricks

我们两清 提交于 2019-12-09 01:50:56
问题 I want to find the number of possible different combinations for a 4 x N area (4 units width and N units height, N ≥ 1) of domino bricks using dynamic programming . Domino bricks have a size of 2x1 e.g. == for a horizontal and | | for a vertical brick. Now, Example 4x1 (two domino bricks beneath each other) ==== Examples for 4x2 brick configurations (5 in total) 1) |||| |||| 2) (Turn two bricks on the right) ||== ||== 3) |==| |==| 4) ==== ==== 5) ==|| ==|| Number of unique combinations known

Text Justification Algorithm

萝らか妹 提交于 2019-12-08 15:31:58
问题 This is a very famous problem in DP, Can somebody help to visualize the recursion part of it.How are the Permutations or Combinations will be generated. problem reference. https://www.geeksforgeeks.org/dynamic-programming-set-18-word-wrap/ 回答1: Given the maximum line width as L, the idea to justify the Text T, is to consider all suffixes of the Text (consider words instead of characters for forming suffixes to be precise.) Dynamic Programming is nothing but "Careful Brute-force". If you

dynamic programming: finding largest non-overlapping squares

谁说我不能喝 提交于 2019-12-08 14:09:11
问题 I really have no idea how to do this using dynamic programming: Problem: I need to find the 2 largest non overlapping squares of a table For example: 5 6 R F F R R F F F F F F F R R F F F F F F F F F F F F F F F F The numbers 5 and 6 are the number of rows and columns respectively, and “R” means reserved and “F” means free. In this case the largest square is F F F F F F F F F F F F F F F F and the second largest (non-overlapping with the previous one) is F F F F So far I have put the values

grid move algorithm implementation in dynamic programming

拟墨画扇 提交于 2019-12-08 09:50:41
问题 Working on below problem, Problem , Given a m * n grids, and one is allowed to move up or right, find the different paths between two grid points. I write two different versions of code, both are using dynamic programming (I tested it seems both of them return the same result)? One version of algorithm has the assumption that if move r steps right, u steps up, we can find (1) solutions for r-1 steps right and u steps up, then combine with one final right step (2), solutions for r steps right

What's the time complexity of this algorithm for Palindrome Partitioning?

懵懂的女人 提交于 2019-12-08 08:50:58
问题 Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Personally I think, the time complexity is O(n^n), n is the length of the given string. Thank you Dan Roche , the tight time complexity = O(n* (2^n)), check details below. #include <vector> using namespace std; class Solution { public: vector<vector<string>> partition(string s) { vector<vector<string>> list; vector<string> subList;

Dynamic programming doesn't give correct answer

谁说我不能喝 提交于 2019-12-08 07:50:34
问题 I recently found out about the technique called dynamic programming and I stumbled upon a problem which I can't figure out. You are given a list of arguments in the beginning and you need to do sums on as if you were cutting it. If the list has only one element, you don't sum it. If it has more, you sum the elements and cut it in every possible way. So if list has n elements, there are just n-1 ways to cut it. The picture will explain: I first wanted to sum up all of the sumable parts and I

How to solve this by recursion?

微笑、不失礼 提交于 2019-12-08 06:54:48
问题 I required some help in solving this question by recursion. Question: A lazy tourist wants to visit as many interesting locations in a city as possible without going one step further than necessary. Starting from his hotel, located in the north-west corner of city, he intends to take a walk to the south-east corner of the city and then walk back. When walking to the south-east corner, he will only walk east or south, and when walking back to the north-west corner, he will only walk north or

How to find the minimum number of operation(s) to make the string balanced?

£可爱£侵袭症+ 提交于 2019-12-08 06:38:30
问题 From Codechef: A string is considered balanced if and only if all the characters occur in it equal number of times. You are given a string S ; this string may only contain uppercase English letters. You may perform the following operation any number of times (including zero): Choose one letter in S and replace it by another uppercase English letter. Note that even if the replaced letter occurs in S multiple times, only the chosen occurrence of this letter is replaced. Find the minimum number

Boolean Mode Where Match Query with Dynamic Against Values, using PHP MySQLi Prepared Statements

有些话、适合烂在心里 提交于 2019-12-08 05:22:51
问题 I want to query mysql with a Where Match query using mysqli prepared statements . The problem is the Boolean Mode AGAINST values , normally: (+value1 +value2 +value IN BOOLEAN MODE) but the problem is that I can't use it in prepared statements e.g. (? ? ? IN BOOLEAN MODE) because the number of values will differ, its not fixed. I tried this code: $keywords = explode(" ", $SearchResults->squery); foreach($keywords as $key=>$value) { $keywords[$key] = '+'.$value; } $keywords = implode(",",

maximizing profit for given stock data via DP

旧时模样 提交于 2019-12-08 05:11:19
问题 You are given the stock prices for a set of days . Each day, you can either buy one unit of stock, sell any number of stock units you have already bought, or do nothing. What is the maximum profit you can obtain by planning your trading strategy optimally? Now the answer can be obtained through single pass but what if it has to be solved through Dynamic Programming. What will be the recurrence relation then for the problem? I think for any day OPT(i) can denote maximum profit earned so far,