If we look at the final result vertically, the number of each column can be regarded as a K-hexadecimal number. There is a total of D columns, and any two columns are different, therefore, this is a problem of fully arranging D-bit K-in-number. K ^ d is arranged in total. If K ^ d <n,-1 is printed.
When the final result is printed, set the first column to 1 1 1... 1. Then, add 1 to each column in sequence (the bus number starts from 1, not from 0). Note that this is k-based.
# Include <stdlib. h> # include <stdio. h> # include <algorithm> # include <vector> # include <math. h> using namespace STD; int tmpvalue [1001] [1001]; int main () {# ifdef _ debugfreopen ("D: \ in.txt", "r", stdin ); # endifint N, K, D; scanf ("% d", & N, & K, & D); If (k <n) {int Total = 1; for (INT I = 1; I <= D; I ++) {total * = K; If (total> = N) {break ;}} if (total <n) {printf ("-1 \ n"); Return 0 ;}}for (INT I = 1; I <= D; I ++) {tmpvalue [I] [1] = 1 ;}for (INT I = 2; I <= N; I ++) {for (Int J = 1; j <= D; j ++) {tmpvalue [J] [I] = tmpvalue [J] [I-1];} tmpvalue [1] [I] + = 1; for (Int J = 1; j <= D; j ++) {If (tmpvalue [J] [I]> K) {tmpvalue [J] [I] = 1; tmpvalue [J + 1] [I] ++;} elsebreak ;}}for (INT I = 1; I <= D; I ++) {for (Int J = 1; j <= N; j ++) {printf ("% d", tmpvalue [I] [J]);} printf ("\ n");} return 0 ;}
cf459c pashmak and buses print in full order