title: How to the "decision/path" during recursion?
body: <p><br>
  I want to calculate the minimal costs in production by choosing lot sizes with recursion. The value I get is correct, but I also want to save the correct decisions/path(how much to produce in each period n).<br> I don't know how to save it correctly. This way I just overwrite it everytime.<br><br>
  n = period, i = inventory, pcap = production capacity, demand[n] = how much i sell in period n,<br>
  Thanks!</p>
  
  <pre><code> public double getMinC(int n, int i) {
          if(demand[n]-i &gt; pcap) return Double.MAX_VALUE;
          if(this.n == n) {
              if(demand[n] &lt; i) {         //not sure if i need this
                  decision[n] = 0;
                  return storagecost * i-demand[n];
              }
              decision[n] =  demand[n]-i;
              return varc * demand[n]-i + fixc;
          }
          double min = Double.MAX_VALUE;
          double cost = min;
          int xmin = Math.max(0, demand[n] - i);
          int xmax = Math.min(storagecap-i+demand[n], pcap);
          int bestx = -1;
          for(int x=xmin; x&lt;=xmax; x++) {
              cost = getMinC(n+1, i+x-demand[n]) + storagecost * (i+x-demand[n]);
              if(x!=0) cost += fixc + varc * x;
              if(cost&lt; min) {
                  min = cost;
                  bestx = x;
              }
          }
          decision[n] = bestx;
          return min;
      }
  </code></pre>