daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int findSum(int* arr, int start, int end) {
  5.     int sum = 0;
  6.     for (int i = start; i < end; i++) {
  7.         // sum += arr[i];
  8.         sum += *(arr+i);
  9.     }
  10.     return sum;
  11. }
  12.  
  13. bool solve(int *original, int *arr,int remainIndex, int currentIndex, int sum) {
  14.     if (findSum(arr, 0, 8) > sum) {
  15.         return false;
  16.     }
  17.     if (findSum(arr, 0, 8) + findSum(original, remainIndex, 8) < sum) {
  18.         return false;
  19.     }
  20.        
  21.     arr[currentIndex] = original[remainIndex];
  22.     if (solve(original, arr, remainIndex + 1, currentIndex + 1, sum))
  23.         return true;
  24.     else {
  25.         arr[currentIndex] = 0;
  26.         return solve(original, arr, remainIndex + 1, currentIndex, sum);
  27.     }
  28.    
  29.     return false;
  30. }
  31.  
  32.  
  33. int main() {
  34.  
  35.     int original[] = { 5,10,12,13,15,18 };
  36.     int answer[6] = { 0 };
  37.  
  38.  
  39.  
  40.  
  41.  
  42.     return 0;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top