Well, you've got two sub problems here. The first is to generate permutations of the input list with certain restrictions. The second is to find a maximal value for the sum of a valid permutation.
One way to do it in C/C++ would be to represent each solution to the problem as a binary number with ones indicating the coupons a user took. So if I took the coupons from stores 1,3,5,7,9 the solution would look like '1010101010' . You can then write a function to convert a bit vector like this to sum using the input numbers.
Now that yoou have a representation for the solutions, you'll need an array to store them in. You could safely make this array global and have a function which adds solutions to the array, and another function that calulates the maximum value by iterating over this array, converting the bitvectors to integers representing the total value of the coupons they represent.
So that just leaves finding the permutations. Since the problem says you can't get coupons from any adajacent store you can write a recursive function that takes an index value and a partial solution, that iterates over all legal stores further down the line from itelf, and calls itself on those stores. (I know that was confusing so maybe a bit of code would explain it more clearly)
Code:
/* hop from store to store */
void find_next_valid_store(int index, int solution_vector) {
for (int i=index+1;i<10;i++) {
/*find the next non-adjacent store from index */
int valid_store = i + 1;
/*add this storeplus any previous stores to our list as a possible solution */
int new_solution = update_bitvector(solution_vector, valid_store);
add_solution( new_solution);
find_next_valid_store(valid_store, new_solution);
}
}
/* all valid solutions could be found by starting at each store and then running find_next_valid */
for(int i=0; i < 10; i++) {
find_next_valid_store( i, make_bitvector_starting_at( i ) );
}