Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. bool sumsTo(unsigned int x[], unsigned int n, unsigned int k, unsigned int v) {
  2.     if (v == 0 && k == 0) { return true; }  // sum = 0 and elemLeft = 0
  3.     if (v < 0 || n == 0) { return false; }  // negative, not possible or array empty
  4.     return (sumsTo(x, n - 1, k - 1, v - x[n - 1]) || sumsTo(x, n - 1, k, v));       // three line solution fuck yeah
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement