title: How to get set of operations in dynamic programming
body: <p>I would like to ask you how can I get a list of operations I have to do to obtain the result. </p>
  
  <p>The simple example:</p>
  
  <p>There is a number N. Your goal is to find out the minimum operations (x/3, x/2, x-1) you have to do to get 1.</p>
  
  <p>So for example minop(10) = 3 (because <strong>1.</strong> 10-1=9, <strong>2.</strong> 9/3=3, <strong>3.</strong> 3/3=1).</p>
  
  <p>This function is very simple with bottom-up approach in Python:</p>
  
  <pre><code># the opt is an optimum nuber of operations for index to get to one
  # the op list should be a list of operations but it does not work
  # correctly. For minop(10) would return opt = 3 (three
  #operations), op = [1,3,3] (minus one, divide three, divide three)
  
  opt = [0,0,0,0,0,0,0,0,0,0,0,0] # optimum number of operation for i
  op = []
  
  def minop(n):
      opt[1]=0
      for i in range(2,n+1):
          opt[i]=opt[i-1]+1
          op.append(1) # INCORRECT
          if i%2==0:
              opt[i] = min(1+opt[i/2],opt[i])
              op[-1]=2 # INCORRECT
          if i%3==0:
              opt[i] = min(1+opt[i/3],opt[i])
              op[-1]=3 # INCORRECT
      return opt[n],op
  </code></pre>
  
  <p>As you can see, the op list should contain minimum list of operations (represented by numbers) needed to get from <code>n</code> to <code>1</code> but it contains.</p>