title: Leetcode House robber
body: <p>I was trying <a href="https://leetcode.com/problems/house-robber/" rel="noreferrer">House Robber</a> problem(dp problem) on leet code.
  This solution from one of the user GYX looks simple and elegant.</p>
  
  <pre><code>   int rob(vector&lt;int&gt;&amp; num) {
     int n = num.size();
          if (n==0) return 0;
          vector&lt;int&gt; result(n+1,0);
          result[1] = num[0];
          for (int i=2;i&lt;=n;i++){
              result[i] = max(result[i-1],result[i-2]+num[i-1]);
          }
          return result[n];
     }
  </code></pre>
  
  <p>But I just could not get my head around the logic. Please help me with the logic and also how to approach problems like this?</p>