I’m working with a memoized version of the Fibonacci series using a custom class that represents integers as strings, and when I try to calculate anything large it throws a stack overflow error. operator- works as intended. Here is the code that throws the error, any help would be appreciated. BigInt Fibonacci(BigInt b) { static ..

#### Category : dynamic-programming

I’ve been trying to insert a key and a value into a map to memoize a Fibonacci function using a custom BigInt class that stores a vector of chars, and it keeps throwing me an assertion error. I’ve tried all different ways of inserting and none will work. Here’s the code that’s causing problems. Any ..

A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes n units of time for a string of length n, regardless of the location of the cut. Suppose, now, that you want to break a string into many pieces. The ..

When I am changing the order of isPossible function then it’s giving wrong answer otherwise present code gives correct answer. I wanted to know why this is happening. Here is the problem statement: https://leetcode.com/problems/partition-equal-subset-sum/submissions/ Here is my accepted solution class Solution { unordered_map<int, bool> um; public: bool isPossible(vector<int>&nums, int currentIndex, int sum){ if(sum == 0){ ..

please tell me what’s wrong with my approach for SPOJ-TOURIST problem. I know the better approach for this problem with 2 tourists O(n^3) solution. But i want to know we cannot solve this question like this. what I tried to do is that I first assumed the tourist to go south-east(with flag value as 0) ..

There are N stones lying in a line. The cost and type of the ith stone is a[i] units and i respectively. You are initially having zero stones and you wish to collect all the N types of stones, type 1, type 2,…..,type N. You can perform the following operation multiple times (probably zero) to ..

Hello i need to adapt some problems with dynamic programming to work with more than the conventional number of objects that they usually works like adapt the knapsack problem to work with N sacks instead of 1 and Longest Common Subsequence to work with N strings instead the usual 2. I found that one way ..

This is my first stack overflow question. I will attempt to provide a thorough description of my problem and ask specific questions. I am doing a programming task on an online judge that requires me to return the nth term of the fibonacci sequence mod m, where m is an integer such that 1 ≤ ..

I have encountered the minimum coin change problem on CodeChef and CodeForces. On both sites I have submitted my implementation using DP. This implementation given TLE error on both sites. Unfortunately, I cannot find any other implementation of this problem. I am linking the problems – CodeChef – https://www.codechef.com/problems/FLOW005 CodeForces – https://codeforces.com/problemset/problem/996/A Here is my ..

I was solving this(https://www.hackerrank.com/challenges/coin-change/copy-from/188149763) problem on Hackerrank which can be summarized as follows : Find the total number ways to exchange a certain value with the given set of coin denominations. Here is my code which got accepted: long getWays(int n, vector<long> c) { long dp[n+1]; memset(dp, 0ll, sizeof(dp)); dp[0] = 1; for(int ci=1; ci<=c.size(); ..

## Recent Comments