Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Of course it depends if your problem is always limited to that constraints, I mean int[8] array, 0-31, and 3-5, but if it isn't, I guess your problem couldn't be solved by a naive algorithm.</p> <p>I mean, let's say we have this array:</p> <pre><code>int[] = new int[] { 2,3,4,5,6,7,8,9,10,11,12 }; </code></pre> <p>and your subset constraint, i.e. <em>"consecutive numbers sets must be from minimum length of 3 and a max of 5 numbers"</em>.</p> <p>A naive algorithm that starts from the first element to the last and fills the biggest possible consecutive subset, will yield these two subsets:</p> <p><code>[2,3,4,5,6] [7,8,9,10,11]</code> </p> <p>In this solution 12 is in no partitions, but obviously there is another feasible solution (actually more than one) that includes all the numbers, that is for example:</p> <p><code>[2,3,4,5] [6,7,8,9] [10,11,12]</code></p> <p>Therefore, you can have several possibilities:</p> <ol> <li>The 1st solution is OK, you don't need to cover as much as possible a found consecutive set</li> <li>The 2nd solution is OK, you need to cover as much as possible a found consecutive set</li> <li>The 2nd solution is OK, you need to cover as much as possible a found consecutive set, and possibly with the lowest possible number of subset</li> </ol> <p>In the first case, you can do as other answerer pointed out (hey man, Jon Skeet answered to you ! :P).<br> Conversely, in the 2nd and 3rd case it's much more complicated because it's a <a href="http://en.wikipedia.org/wiki/Knapsack_problem" rel="nofollow">Knapsack type problem</a> i.e. an NP complete problem, (the 3rd case in particular sounds to me like <a href="http://en.wikipedia.org/wiki/Change-making_problem" rel="nofollow">Change-making problem</a>). </p> <p>That's my two cents, obviously, I repeat, the problem doen't exist if you have always the same array size, range and subset constraints...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload