# Tag Info

2

Dynamic Programming can be used to solve a problem as long as the problem has a recursive substructure and the sub-structural problems are overlapping. So, as long as a problem has the two properties, DP can be user for solving it. Problems with these properties are definitely not restricted to only optimization problems. So, yes. Here are some good ...

1

I will describe a method running in $O(|n|) = O(\log n)$ where $|n|$ is the length of the number written in decimal representation. We will follow a dynamic programming scheme. For each $k \in \{0, \dots 10\}$ and each positive integer $j \leq n$ we will compute the number of integers of length $k$, whose sum of digits is equal to $k$. This can be computed ...

1

Intuitively I understand that the reason why the function became less efficient is because it avoids solving the right subproblem sometimes, which means that it also memoizes less cases, which in turn makes it perform more work. This is impossible. Not solving and memoizing a subproblem can never make the algorithm slower. Either the subproblem will never ...

1

It turned out we can achieve it in $O(nM)$ time where $n$ is the number of distinct items in the store, and $M$ is the final bill. We can build a 2-dimensional array with size $C[T, M]$ as follows: $C[i, j] = 1$, if there exists a way to add items from $\{t_1,t_2,...,t_i\}$ that adds up to $M$. $C[i, j] = 0$, if we cannot find items that adds up to $M$. ...

1

One possible approach to solve this problem is as follows:- (1) Create a trie of the dictionary for fast matching. (2) Create a recursive function that does the following:- (a) Finds all possible prefixes of the current string that are present in the dictionary. (b) Calls itself recursively with those prefixes removed Example:- Word:- keyboardrocks ...

Only top voted, non community-wiki answers of a minimum length are eligible