All Questions
Tagged with dynamic-programming python-3.x
134 questions
0
votes
2
answers
70
views
dynamic programming: (minimum days of not eating icecreams)
Minimum Days Not Eating Ice-cream
Ram decides to eat ice-cream for N days. On each day the ice-cream shop can have chocolate flavour or mango flavour or both or none. The availability of ice-cream ...
0
votes
1
answer
48
views
Number of hits in fibonacci using lru_cache
I am using functools.lru_cache to implement Fibonacci using memoization. But I do not understand the number of hits that my output generates. My code is as follows:
@lru_cache(maxsize=8)
def fib(n):
...
1
vote
3
answers
93
views
Update every nth element of given a range
I have N=12
and between 1 to 12 (in N) I want every 3 elements to be updated.
For example:
I am calculating the current hour(say 6am) and add 4 hours to start with "6-10" for the 1st 3 rows ...
0
votes
1
answer
337
views
Trouble Solving Maximum Product Subarray
I am trying to solve LeetCode problem 152. Maximum Product Subarray:
Given an integer array nums, find a subarray* that has the largest product, and return the product.
The test cases are generated ...
1
vote
1
answer
112
views
Tabulation (Dynamic Programming) using Decorator
Find the Factorial of a number by tabulation using decorators
def factorial(n):
if n<1:
return 1
else:
f=[0]*(n+1) #creation of the array/list#
f[0]=1 ...
1
vote
0
answers
22
views
Inconsistent output on leetcode and vs code [duplicate]
class Solution:
def combinationSum4(self, nums: List[int], target: int,memo={}) -> int:
if target in memo:
return memo[target]
if target==0:
return 1
...
1
vote
3
answers
81
views
Every Potential Combination of a Number from a List
I'm attempting to generate all conceivable combinations of a given number using elements from a list. For instance, when the number is 4 and the list contains [1, 2], there are 3 possible combinations:...
6
votes
1
answer
384
views
Is there any true general pattern to solve any dynamic programming problems?
I understand there is a general pattern to solve dynamic programming problems. Consists of:
Identify Overlapping Subproblem by Breaking down the problem into smaller subproblems that are solved ...
0
votes
1
answer
51
views
Python acting in a strange way (Dynamic Programing) [duplicate]
I have written this following code that takes an integer N and and array of integers: arr. The task is to find the shortest combination of the integers in arr that sum up to N . Each elements of arr ...
0
votes
0
answers
126
views
How to find out phonenumbers based on (chess) knight moves
So basically in this problem we have a knight (from chess) and a keypad from a phone. Using the possible moves for knight (i.e. 'L' shape) we have to find the total count of phone numbers that can ...
0
votes
1
answer
30
views
How the local instance is not reset during an recursive call in python
I was practicing a problem to find the nth number of a Fibonacci series using dynamic programming.
Here is my python code:
def fib(n,memo=[1,1]):
if n<=len(memo):
return memo[n-1]
...
0
votes
1
answer
626
views
How to edit the parameter in the decorator dynamically in the runtime in Python
can anyone help me to make the "FROM" variable dynamic in the decorator in the runtime?
The script is a message forwarder, in the beginning it is working with the Chat IDs I provide in FROM ...
0
votes
3
answers
2k
views
Function to dynamically extract values from multiple nested dictionary in Python
The problem statement is to write a function which will take a input dictionary object and return a list of all the values, even in case of multi-level nested dictionaries inside the input dictionary ...
0
votes
1
answer
260
views
Solving Knapsack Problem for large dataset using PULP library in Python
I have the below dataframe:
import itertools
import pandas as pd
import numpy as np
p1_values = np.arange(19, 29.1, 0.1)
p2_values = np.arange(23, 33.1, 0.1)
p3_values = np.arange(36, 46.1, 0.1)
...
1
vote
1
answer
211
views
What is an alternative to using `__getattr__()` method for wrapper classes?
Suppose that I have two classes:
a class named Swimmer
a class named Person
For my particular application, we can NOT have Swimmer inherit from Person, although we want something like inheritance.
...