#include #include #include int main(int argv, char **argc) { if (argv < 3) { assert(argv > 0); printf("Usage: %s [n] [t]\n", argc[0]); return -1; } size_t n = atoi(argc[1]), t = atoi(argc[2]); assert(1 < t && t < n); size_t *c = calloc(t + 2, sizeof(*c)); size_t j; R1_initialize: for (size_t j = 1; j <= t; j++) c[j] = j - 1; c[t + 1] = n; R2_visit: for (size_t k = t; k >= 1; k--) printf("%lu ", c[k]); printf("\n"); R3_maybe_easy_case: if ((t % 2) == 1) { if (c[1] + 1 < c[2]) { c[1] = c[1] + 1; goto R2_visit; } j = 2; goto R4_try_decrease_c_j; } else { if (c[1] > 0) { c[1] = c[1] - 1; goto R2_visit; } else { j = 2; goto R5_try_increase_c_j; } } R4_try_decrease_c_j: if (c[j] >= j) { c[j] = c[j - 1]; c[j - 1] = j - 2; goto R2_visit; } j = j + 1; R5_try_increase_c_j: if (c[j] + 1 < c[j + 1]) { c[j - 1] = c[j]; c[j] = c[j] + 1; goto R2_visit; } else { j = j + 1; if (j <= t) goto R4_try_decrease_c_j; } }