title: Split a set of size N into M groups with minimum difference between sums of these groups
body: <p>There is a set of size <code>N &lt;= 50</code> of positive numbers. <strong>This set cannot be sorted or changed</strong>!!!</p>
  <pre><code>S = {n1, n2, n3, ..., nN}
  </code></pre>
  <p>I need to split the set <code>S</code> on <code>M &lt;= 25</code> groups:</p>
  <pre><code>Groups = {{n1, n2}, {n3, n4, n5...},...,{... nN}} -&gt; len(Groups) = M
  </code></pre>
  <p><strong>The maximum difference between two adjacent groups should be as less as possible.</strong>
  Difference is calculated in such way:</p>
  <pre><code>diff = abs(sum(G1) - sum(G2)) = abs((n1 + n2) - (n3 + n4 + n5))
  </code></pre>
  <p>I could generate all vectors of size <code>N</code> that contain only <code>M</code> non-zero digits (like <code>1</code>) but I will be obliged to consider <code>50! / (25! * 25!)</code> for brute force that is wrong :(</p>
  <p>Example:</p>
  <pre><code>6, 13, 10, 2
  case 1: {6}, {13, 10, 2} -&gt; difference = 25
  case 2: {6, 13}, {10, 2} -&gt; difference = 5
  case 3: {6, 13, 10}, {2} -&gt; difference = 29
  The best case is second -&gt; difference = 5!
  </code></pre>
  <p>What an idea can I use to solve this problem?</p>