title: Selecting such vector elements so that the sum of elements is exactly equal to the specified value
body: <p>I have a vector of random positive integers. I would like to select only those elements of the vector whose sum will be exactly equal to a certain predetermined value.</p>
  <p>Let's take an example like this.
  <code>x=1:5</code>, I am looking for elements whose sum is equal to <code>14</code>. The solution is of course the vector <code>c(2, 3, 4, 5)</code>.</p>
  <p>Of course, there may be several solutions.
  Example 2.
  <code>x=1:5</code>, I'm looking for elements whose sum is equal to <code>7</code>.
  Here, of course, should be the following three solutions:<br />
  1.<code>c(2, 5)</code>,<br />
  2.<code>c(3, 4)</code>,<br />
  3.<code>c(1, 2, 4)</code>.</p>
  <p>There may also be a situation where there will be no solutions at all.
  Example 3.
  <code>x=c(1, 2, 7)</code>, I'm looking for elements whose sum equals <code>5</code>.
  Of course, there are no correct solutions here.</p>
  <p>Everything seems trivially simple if we have vectors of several elements. Here, I even came up with a few alternative solutions. However, the problem becomes when the size of the vector increases.</p>
  <p>My vector looks like this:</p>
  <pre><code>x= c(236L, 407L, 51L, 308L, 72L, 9787L, 458L, 5486L, 42L, 4290L,
    31L, 3533L, 1102L, 24L, 100L, 669L, 9352L, 4091L, 2751L, 3324L,
    3193L, 245L, 86L, 98932L, 77L, 13L, 9789L, 91L, 999L, 25L, 25379L,
    9626L, 9092L, 622L, 97L, 57L, 2911L, 6L, 405L, 894L, 1760L, 9634L,
    96L, 9765L, 223L, 765L, 743L, 5960L, 14L, 50L, 89L, 348L, 5875L,
    5L, 58602L, 397L, 1181L, 94L, 954L, 7901L, 836L, 8810L, 52L,
    15L, 48L, 26L, 4L, 66L, 5265L, 80L, 282L, 231L, 76L, 661L, 7604L,
    7406L, 58L, 10L, 903L, 49446L, 80921L, 1L, 876L, 334L, 63L, 796L,
    88L, 413L, 1214L, 2983L, 9518L, 595L, 708L, 53L, 321L, 12L, 634L,
    4910L, 8984L, 465L)
  </code></pre>
  <p>I have to find at least one subset of elements whose sum will be exactly <code>23745</code>.
  Unfortunately, I had a complete failure here. Whatever I write is calculated in hours and I don't get any correct result anyway. Does anyone have any idea how this can be solved in R? I will be grateful for even a small hint.</p>