title: TSP using Dynamic Programming
body: <p>I am learning TSP and found this recursive solution to TSP</p>
  
  <pre><code>int compute(int start,int set)
  {   int masked,mask,result=INT_MAX,temp,i;//result stores the minimum 
      if(g[start][set]!=-1)//memoization DP top-down,check for repeated subproblem
          return g[start][set];
      for(i=0;i&lt;n;i++)
          {   //npow-1 because we always exclude "home" vertex from our set
              mask=(npow-1)-(1&lt;&lt;i);//remove ith vertex from this set
              masked=set&amp;mask;
              if(masked!=set)//in case same set is generated(because ith vertex was not present in the set hence we get the same set on removal) eg 12&amp;13=12
              {   
                  temp=adj[start][i]+compute(i,masked);//compute the removed set
                  if(temp&lt;result)
                      result=temp,p[start][set]=i;//removing ith vertex gave us minimum
              }
          }
          return g[start][set]=result;//return minimum
  }
  </code></pre>
  
  <p>I could not understand How masking is working , How can change it to Dynamic programming solution without using recursion , please help me.</p>