dynamic-programming

Memory-constrained coin changing for numbers up to one billion

别来无恙 提交于 2020-01-11 15:49:37
问题 I faced this problem on one training. Namely we have given N different values ( N<= 100 ). Let's name this array A[N] , for this array A we are sure that we have 1 in the array and A[i] ≤ 10 9 . Secondly we have given number S where S ≤ 10 9 . Now we have to solve classic coin problem with this values. Actually we need to find minimum number of element which will sum to exactly S . Every element from A can be used infinite number of times. Time limit: 1 sec Memory limit: 256 MB Example: S =

A way to dynamically create variables in Matlab?

柔情痞子 提交于 2020-01-11 07:25:35
问题 The case I am working on is dividing a big three-dimensional array of data that I have collected using good coding practises (etc...) and now I need to segment the layers of this array into separate variables for individual processing elsewhere, I can't call my data like this BigData(:,:,n) . So I would like to create a loop where I create new variables like so for i=1:n createVariable('user_' i) = BigData(:,:,i); end How do I do this without writing n new variables by hand every time? user_1

How do I replace a method implementation at runtime?

这一生的挚爱 提交于 2020-01-09 08:11:19
问题 I'd like to have property getters and methods that I can decorate with my own custom attribute and based on the presence of that attribute replace the method bodies with a different implementation. Also, that different implementation will need to know the constructor arguments given to the custom attribute where it decorates the method. This can obviously be done with AOP, like PostSharp or LinFu, but I'm wondering if there's a way to do this that does not involve a post-build processing step

How do I replace a method implementation at runtime?

微笑、不失礼 提交于 2020-01-09 08:11:05
问题 I'd like to have property getters and methods that I can decorate with my own custom attribute and based on the presence of that attribute replace the method bodies with a different implementation. Also, that different implementation will need to know the constructor arguments given to the custom attribute where it decorates the method. This can obviously be done with AOP, like PostSharp or LinFu, but I'm wondering if there's a way to do this that does not involve a post-build processing step

2D MATRIX statement for 5 x 5 Grid

删除回忆录丶 提交于 2020-01-07 09:30:33
问题 Given a 5 x 5 Grid comprising of tiles numbered from 1 to 25 and a set of 5 start-end point pairs. For each pair,find a path from the start point to the end point. The paths should meet the below conditions: a) Only Horizontal and Vertical moves allowed. b) No two paths should overlap. c) Paths should cover the entire grid Input consist of 5 lines. Each line contains two space-separated integers,Starting and Ending point. Output: Print 5 lines. Each line consisting of space-separated integers

2D MATRIX statement for 5 x 5 Grid

二次信任 提交于 2020-01-07 09:30:14
问题 Given a 5 x 5 Grid comprising of tiles numbered from 1 to 25 and a set of 5 start-end point pairs. For each pair,find a path from the start point to the end point. The paths should meet the below conditions: a) Only Horizontal and Vertical moves allowed. b) No two paths should overlap. c) Paths should cover the entire grid Input consist of 5 lines. Each line contains two space-separated integers,Starting and Ending point. Output: Print 5 lines. Each line consisting of space-separated integers

Dynamically choose which properties to get using Linq

偶尔善良 提交于 2020-01-06 18:06:50
问题 I have an MVC application with a dynamic table on one of the pages, which the users defines how many columns the table has, the columns order and where to get the data from for each field. I have written some very bad code in order to keep it dynamic and now I would like it to be more efficient. My problem is that I don't know how to define the columns I should get back into my IEnumerable on runtime. My main issue is that I don't know how many columns I might have. I have a reference to a

Number of ways such that sum of k elements equal to p

[亡魂溺海] 提交于 2020-01-06 15:59:08
问题 Given series of integers having relation where a number is equal to sum of previous 2 numbers and starting integer is 1 Series ->1,2,3,5,8,13,21,34,55 find the number of ways such that sum of k elements equal to p.We can use an element any number of times. p=8 k=4. So,number of ways would be 4.Those are, 1,1,1,5 1,1,3,3 1,2,2,3 2,2,2,2 I am able to sove this question through recursion.I sense dynamic programming here but i am not getting how to do it.Can it be done in much lesser time??? EDIT

Algorithm for cutting rod to maximize profit

天大地大妈咪最大 提交于 2020-01-06 15:06:35
问题 I am trying to solve the standard rod-cutting problem through dynamic programming. As found here and here, the recurrence relations seems to be: prices = [1..n] array[1..n] array[1] = prices[1] for i in (2..n) { array[i] = INT_MIN for j in (1..i-1) { array[i] = max(array[i],prices[j]+array[i-j]) } } And array[n] returns the value for n , which is our answer. My question lies in the line array[i] = max(array[i],prices[j]+array[i-j]) Shouldn't it be array[i] = max(array[i],array[j]+array[i-j])

Algorithm for cutting rod to maximize profit

◇◆丶佛笑我妖孽 提交于 2020-01-06 15:05:10
问题 I am trying to solve the standard rod-cutting problem through dynamic programming. As found here and here, the recurrence relations seems to be: prices = [1..n] array[1..n] array[1] = prices[1] for i in (2..n) { array[i] = INT_MIN for j in (1..i-1) { array[i] = max(array[i],prices[j]+array[i-j]) } } And array[n] returns the value for n , which is our answer. My question lies in the line array[i] = max(array[i],prices[j]+array[i-j]) Shouldn't it be array[i] = max(array[i],array[j]+array[i-j])