<p>You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.</p>

<p>You are given a collection of <code>rods</code> that can be welded together. For example, if you have rods of lengths <code>1</code>, <code>2</code>, and <code>3</code>, you can weld them together to make a support of length <code>6</code>.</p>

<p>Return <em>the largest possible height of your billboard installation</em>. If you cannot support the billboard, return <code>0</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> rods = [1,2,3,6]
<strong>Output:</strong> 6
<strong>Explanation:</strong> We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> rods = [1,2,3,4,5,6]
<strong>Output:</strong> 10
<strong>Explanation:</strong> We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> rods = [1,2]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The billboard cannot be supported, so we return 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= rods.length &lt;= 20</code></li>
	<li><code>1 &lt;= rods[i] &lt;= 1000</code></li>
	<li><code>sum(rods[i]) &lt;= 5000</code></li>
</ul>

class Solution {
public:
    int n;
    int sum =0;
    vector<vector<int>> dp;
    int tallestBillboard(vector<int>& rods) {
        n = rods.size();
        for(int rod : rods) sum += rod;
        dp.resize(n+1,vector<int>(sum+sum+1,-1));
        return welder(0,0,rods)/2;
    }
    int welder(int i, int diff,vector<int>& rods){
        if(i==n && diff==0) return 0;
        if(i==n) return -1e9;
        if(dp[i][diff+sum]!=-1) return dp[i][diff+sum];

        int noWelding = welder(i+1,diff,rods);
        int weldInRod1 = rods[i] + welder(i+1,diff+rods[i],rods);
        int weldInRod2 = rods[i] + welder(i+1,diff-rods[i],rods);

        return dp[i][diff+sum] = max(noWelding,max(weldInRod1,weldInRod2));
    }
};


// rod1 - rod2 = diff  -----------eq 1.
// at i index if x length is rod there 
// if we add in in rod1 :
// (rod1 +x) - rod2  
// (rod1 -rod2 ) + x 
// (from eq1) => diff + x        (when added in rod1) 

//if we add in rod2 
// rod1 - (rod2+x) 
// rod1 - rod2 -x
// (rod1-rod2) -x 
// diff -x (when added in rod2)
48721