zoukankan      html  css  js  c++  java
  • NYOJ 366

    View Code
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int i,j,k,T;
     9     int n;
    10     char str[10]={'1','2','3','4','5','6','7','8','9'};//实际上可以吧10省略 
    11     cin>>T;
    12     while(T--)
    13     {
    14         cin>>n;
    15         k=0;
    16         do 
    17         {
    18             for(i=0;i<n;++i)
    19                 cout<<str[i];
    20              cout<<endl;
    21         }while(next_permutation(str,str+n));
    22     }
    23     return 0;
    24 }        
     1 #include <stdio.h> 
     2 #include <string.h>
     3 #define MAX 10 
     4 bool vis[MAX]; 
     5 int res[MAX]; 
     6 int N; 
     7 void output()
     8 { 
     9     int i; 
    10     for(i = 0; i < N; i++) 
    11         printf("%d", res[i]); 
    12     printf("\n"); 
    13 } 
    14 void dfs(int step)
    15 { 
    16     int i; 
    17     if(step == N) 
    18         output(); 
    19     else
    20     { 
    21         for(i = 0; i < N; i++)
    22         { 
    23             if(!vis[i])
    24             { 
    25                 vis[i] = 1; 
    26                 res[step] = i + 1; 
    27                 dfs(step + 1); 
    28                 vis[i] = 0; 
    29             } 
    30         } 
    31     } 
    32 } 
    33 
    34 int main()
    35 { 
    36     int t;
    37     scanf("%d",&t);
    38     while(t--)
    39     {
    40           memset(vis,0,sizeof(vis));
    41         scanf("%d", &N); 
    42         dfs(0); 
    43     }
    44     return 0;
    45 } 
    46 
    47         
  • 相关阅读:
    CF293E Close Vertice
    [SCOI2016]幸运数字
    [NOI2003]逃学的小孩
    0302读后感
    1231递归下降语法分析
    1210-有穷自动机
    11.12 评论汇总
    1029语言文法
    0921 词法分析
    0909开启编译原理之路
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2677518.html
Copyright © 2011-2022 走看看