Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool sumsTo(unsigned int x[], unsigned int n, unsigned int k, unsigned int v) {
- if (v == 0 && k == 0) { return true; } // sum = 0 and elemLeft = 0
- if (v < 0 || n == 0) { return false; } // negative, not possible or array empty
- 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