You can win three kinds of basketball points, 1 point, 2 points, and 3 points. Given a total score n, print out all the combination to compose n.
Use Dynamic Programming to avoid repetitive computation.
Read full article from Print all combinations of points that can compose a given number | GeeksforGeeks
Use Dynamic Programming to avoid repetitive computation.
void printCompositions(int n, int i)
{
/* array must be static as we want to keep track of values stored in arr[] using current calls of printCompositions() in function call stack*/ static int arr[ARR_SIZE]; if (n == 0) { printArray(arr, i); } else if(n > 0) { int k; for (k = 1; k <= MAX_POINT &&K<=n; k++) { arr[i]= k; printCompositions(n-k, i+1); } }}