Nyoj 366 D's Small L "DFS"

Source: Internet
Author: User

Small l time limit for D:4000Ms | Memory Limit:65535KB Difficulty:2
Describe
One day TC's Marina to find ACM small L play Three Kingdoms kill, but this will be small l busy mile, do not want to play with the marina, but also afraid of the marina, the small l to marina out a topic want to baffle marina (small l very D bar), there is a number n (0<n<10), write 1 to N of the whole arrangement, then marina a little embarrassed,,, Smart can you help Marina to the rescue?
Input
the first line enters a number n (0<n<10), which indicates that there are n sets of test data. The following n lines enter multiple sets of input data, each set of input data is an integer x (0<x<10)
Output
output all combinations in a specific order.
Specific order: The values in each combination are arranged from small to large, and the combinations are arranged in dictionary order.
Sample input
223
Sample output
1221123132213231312321

Simple deep Search;

Code:

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath >const int M = 20;using namespace Std;int N;char ss[m];bool vis[m];const string s = "123456789"; void dfs (int step) {if (s Tep = = N) {Ss[n] = ' + '; cout << SS <<endl; return;} for (int i = 0; i < n; + + i) {if (!vis[i]) {vis[i] = 1;ss[step] = s[i];d fs (step+1); vis[i] = 0;}}} int main () {int t;cin >> t;while (T--) {memset (Vis, 0, sizeof (VIS)), Cin >> n;int i;for (i = 0; i < n; + + i) {SS [0] = s[i];vis[i] = 1;dfs (1); vis[i] = 0;}} return 0;}        


Nyoj 366 D's Small L "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.