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"