title: Need help on Rod Cutting with Memoization
body: <p>I had implelmented the rod cutting using memoization technique in java and here is the code that i have come up so far:</p>
  
  <pre><code>public class RodCutMemo {
  public static int [] memo;
  public static void main(String args [])
  {    int []  prices = {0,2,3,5,8,6,4,9,10,12,15,16,17,18,20,22,31,50} ;
       int n=5;
       memo = new int [n+1]; 
       for(int i =1;i&lt;=n;i++)
       {   memo[i]=-9999;}
       System.out.println(maxProfitRodCutMemo(prices ,n));
  }
  public static int maxProfitRodCutMemo(int [] prices,int n)
  {       if(memo[n]&gt;=0)
          {
          return memo[n];}
      //else if(n==0)
      //{
       // return 0;
      //}
      else
      {   int q = -9999;
          for(int i =1;i&lt;=n;i++)
          {q=Math.max(q,prices[i]+maxProfitRodCutMemo(prices, n-i) );}
          return q;}}}
  </code></pre>
  
  <p>I have two questions here...</p>
  
  <p>Q1)I have commented out one of the base conditions..<code>if(n==0)</code>.Is that required in code.Am i missing some corner case without that??</p>