Xiao Ming (Nanyang 19) (DFS)

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.