Problem: Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times.
Select either first or last element from the given array.
Either increment the selected element by 1 or delete the selected element.

Sample Input: arr[] = {10, 2, 10, 5}, X = 3, K = 3
Sample Output: 1
Explanation:
XOR of the given array = 7. The only possible array satisfying the condition is {10, 2, 10, 8}, obtained by incrementing the last array element thrice.

Solution (cpp):
// C++ program for the above approach

#include <bits/stdc++.h>
using namespace std;

// Stores the final answer
int ans = 0;

// Utility function to count arrays
// having at least K elements exceeding
// XOR of all given array elements
void countArraysUtil(vector<int>& arr,
                     int X, int K,
                     int xorVal)
{
    // If no operations are left
    if (X == 0) {

        // Stores the count of
        // possible arrays
        int cnt = 0;

        // Count array elements are
        // greater than XOR
        for (int i = 0; i < arr.size(); i++) {

            if (arr[i] > xorVal)
                cnt++;
        }
        if (cnt >= K)
            ans++;
        return;
    }
    
    // Stores first element
    int temp = arr[0];

    // Delete first element
    arr.erase(arr.begin());

    // Recursive call
    countArraysUtil(arr, X - 1, 
                    K, xorVal);

    // Insert first element into vector
    arr.insert(arr.begin(), temp);

    // Stores the last element
    temp = arr.back();

    // Remove last element from vector
    arr.pop_back();

    // Recursive call
    countArraysUtil(arr, X - 1, 
                    K, xorVal);

    // Push last element into vector
    arr.push_back(temp);

    // Increment first element
    arr[0]++;
  
    // Recursive call
    countArraysUtil(arr, X - 1,
                    K, xorVal);
  
    // Decrement first element
    arr[0]--;

    // Increment last element
    arr[arr.size() - 1]++;
  
    // Recursive call
    countArraysUtil(arr, X - 1,
                    K, xorVal);
  
    // Decrement last element
    arr[arr.size() - 1]--;
}

// Function to find the count of 
// arrays having atleast K elements 
// greater than XOR of array
void countArrays(vector<int>& arr, 
                 int X, int K)
{
    // Stores the XOR value
// of original array
    int xorVal = 0;

    // Traverse the vector
    for (int i = 0; i < arr.size(); i++)
        xorVal = xorVal ^ arr[i];

    countArraysUtil(arr, X, K, xorVal);

    // Print the answer
    cout << ans;
}

// Driver Code
int main()
{
    // Given vector
    vector<int> arr = { 10, 2, 10, 5 };

    // Given value of X & K
    int X = 3, K = 3;

    countArrays(arr, X, K);

    return 0;
}