Good at arranging James time limit: 1000 MS | memory limit: 65535 kb difficulty: 4
-
Description
-
James is very clever and very good at arranging computing. For example, if you want to give a small number 5, he can immediately give a full array of numbers from 1 to 5 in the lexicographically ordered order. If you want to embarrass him, select a few numbers from these five numbers to keep him in full order, then you are wrong. He is also very good at it. Now you need to write a program to verify whether James is good at sorting.
-
Input
-
The number of groups of test data in the first line is represented by an integer N (1 <n <10,
The first line of each group of test data is two integers n m (1 <n <9, 0 <m <= N)
-
Output
-
In 1-N, select M characters for full sorting, and output all data in lexicographically. Each sort occupies one row, and there is no division between each group of data. Example
-
Sample Input
-
23 14 2
-
Sample output
-
123121314212324313234414243
-
/* The first time I did a search, I really don't understand it. I read others' code and barely typed it out. It's hard to start with everything. I believe it will be better in the future! * // # Include <stdio. h> # include <string. h> int n, m; int visit [100]; // mark the array. Int A [100]; int DFS (int x) {int I; If (x = m) {for (I = 0; I <m; I ++) printf ("% d", a [I]); printf ("\ n") ;}for (I = 1; I <= N; I ++) {If (! Visit [I]) {visit [I] = 1; A [x] = I; // The first number of this sequence. DFS (x + 1); // The next number of search elements. Visit [I] = 0 ;}}int main () {int t; scanf ("% d", & T); While (t --) {memset (visit, 0, sizeof (visit); scanf ("% d", & N, & M); DFS (0 );}}
Xiao Ming (Nanyang 19) (DFS)