title: Segmentation fault with recursion
body: <p>I'm trying to write C++ code for solving <a href="https://leetcode.com/problems/house-robber/" rel="nofollow">house-robber problem</a>. </p>
  
  <p>But my recursion doesn't work, I'm getting Segmentation fault.
  Can't understand what's wrong. Please, take a look</p>
  
  <pre><code>int award(vector&lt;int&gt;&amp; nums, int n, vector&lt;int&gt;&amp; sum)
  {
      if (n == 0) sum[0] = 0;
      if (n == 1) sum[1] = nums[0];
      if (n &gt; 1) 
      {
          if ((sum[n-1]) &lt; 0) sum[n-1] = award(nums,n-1,sum);
          if ((sum[n-2]) &lt; 0) sum[n-2] = award(nums,n-2,sum);
          sum[n] = max(sum[n-2] + nums[n-1], sum[n-1]);
      }
      int ans = sum[n];
      return ans;
  }
  
  int main() 
  {
      vector&lt;int&gt; nums;
      vector&lt;int&gt; sum (100); 
      int a;
      int i = 0;
      while (cin&gt;&gt;a)
      {
          nums[i] = a;
          i++;
      }
      int n = nums.size();
      for(int i = 0; i &lt;= n; i++)
      {
          sum[i] = -1;
      }
      cout&lt;&lt;award(nums,n, sum);
  }
  </code></pre>