title: Runtime error: reference binding to null pointer of type 'int'
body: <p>I am solving the <a href="https://leetcode.com/problems/house-robber/" rel="nofollow noreferrer">House Robber</a> problem on Leetcode and I am getting a &quot;Runtime error: reference binding to null pointer of type 'int'&quot;. Why is this error occuring?</p>
  <p>My code:</p>
  <pre><code>  class Solution {
    public:
      int rob(vector&lt;int&gt;&amp; a) {
          int n=a.size();
          vector&lt;int&gt; dp(n);
          for(int i=0;i&lt;n;i++)
              dp.push_back(0);
          dp[0]=a[0]; dp[1]=a[1];
          int ans=0;
          for(int i=2;i&lt;n;i++)
          {
              dp[i]+=dp[i-2]+a[i];
              ans=max(ans,dp[i]);
          }
              
          return ans;
      }
  };
  </code></pre>