Nyoj 19 is good at arranging James and nyoj19 is good at arranging
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
-
Simple recursive exercises, 24
-
# Include <stdio. h> # include <string. h> int a [10], v [10], n, m; // The v array is used to determine whether it has been accessed. array a stores the void dfs (int c) number used) {if (c> m) {// c> m indicates that there are m numbers in the array, and the output is for (int I = 1; I <= m; I ++) printf ("% d", a [I]); printf ("\ n");} else {for (int j = 1; j <= n; j ++) {// use a loop to find out which number is suitable for if (! V [j]) {// If j is suitable for a [c] = j; // c indicates that the number of c stored in the array is v [j] = 1; dfs (c + 1); // recursive v [j] = 0 ;}}} int main () {int t; scanf ("% d", & t ); while (t --) {memset (v, 0, sizeof (v); scanf ("% d", & n, & m); dfs (1 );} return 0 ;}