So I made a program that takes in three strings, A, B, and C and determines whether or not C is a merge of A and B. A merge is defined as combination of the letters in A and B such that the ordering of the letters of A and B in relation to one ..

#### Category : dynamic-programming

Example: I have two 10 foot boards. I want to saw those boards into pieces of 6", 5", 4", 3" and 2". So I use my first board to saw a 5" piece and a 4" piece. I use my second board to get 6" and 3" coins. I end up with two 1" scraps ..

I am getting a runtime error in some test cases when I try to submit my code. Problem Link: https://atcoder.jp/contests/dp/tasks/dp_a My code: #include<bits/stdc++.h> using namespace std; #define int long long int minCost(int n, vector<int> h, vector<int> dp) { if (dp[n] != -1) { return dp[n]; } if (n == 1) { return dp[n] = 0; ..

Given two random substrings (not necessarily same length) with only English letters, find the best common approximate substrings using dynamic programming. Each letter has a weight w of given value (i.e. set A with weight 1, B with 2, or all letters to 1), and penalty p of a random value. The best "common approximate ..

I need permutate some integers but without repeating and with condition so for example i have 4 place where i can put integers for every place i have array of integers which can be placed there so i need to know how many ways i can permutate it itegers for permutation : 8,6,1 – 1 ..

I am trying to implement a bottom up approach function to the rod cutting problem and I need to use this particular pseudo-code from the CLRS textbook. In it there two functions and one calls the other in this fashion (r,s) = EXTENDED-BOTTOM-UP-CUT-ROD(p,n) Where r and s are two different arrays. The function also returns ..

I need to deliver due tomorrow a coding problem to my university and it goes like this: Given an array of numbers, divide the array into K subarray such that it maximizes the product. Example: Input: 3 3 2 1 Output: {3, 3}, {2, 1} I am asked to use dynamic programming (tabulation), can I ..

I am trying to solve a problem with memset, but I am trying to get the combination of shots that can give me 5. I don’t know if I am using the memset function correctly to solve a dynamic programming problem, although I have a slight perception that I am. My intention with this code ..

I’m trying to memoize this unique paths grid problem. Until now, I always put the memoized return statement on top of the function. But here, it’s not working. I don’t understand why. Do those positions matter sometimes? Can you please explain the reason? I have just started dynamic programming. int grid(long long i, long long ..

Suppose we have n Integer elements (a1,a2,…,an) where (1<= a[i] <= 255). We need to find the best k integer values (v1,v2,…,vk) which will minimize the formula: Note that (a1,…,an) and k are given as input and we need to return the minimum value for the formula. Approach: We know that if k=1, v[0] must ..

## Recent Comments