#include
#include
/* For i=0,1,2,...,k-1, B[i] stores the first index from which i+1 starts
* in A[]. The array A[] itself is neither created nor maintained.
* Initially, B[0] = 0 to indicate that 1 starts from index 0 in A[].
* Also, we set B[k] = n for printing convenience to indicate that k+1
* starts at index n in A[].
*
* n, k are the integers supplied by the user.
*
* t is the current integer for which the starting index in A[] is to be
* determined.
*/
int genidxarr ( int *B, int n, int k, int t )
{
int i, j, cnt = 0;
/* If the starting indices are fixed for 1,2,...,k, we have detected
* one valid arrangement. Print it and return 1.
*/
if (t == k+1) {
for (i=1; i<=k; ++i) {
/* Print the requisite number of i's. Note that in A[], i starts
* from index B[i-1], and i+1 starts from index B[i].
*/
for (j=B[i-1]; j