Xiao Ming's time constraints that are good at arrangement: 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 ProgramTo 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
It's just a simple application of next_permutation ().
# Include <stdio. h >#include <algorithm> # include <iterator> using namespace STD; int main () {int n, m, n; int last [10] = {0 }; scanf ("% d", & N); While (n --) {int A [10] = {1, 2, 4, 5, 6, 7, 8, 9 }; scanf ("% d", & M, & N); do {If (! Equal (A, A + N, last) {copy (A, A + N, last); For (INT I = 0; I! = N; I ++) // amount. You only need to output the first n digits. {printf ("% d", a [I]);} puts ("") ;}}while (next_permutation (A, A + M ));}}