• 输出1-n的全排列dfs


     https://ac.nowcoder.com/acm/contest/998/C

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<vector>
    #include<cmath>
    #include<string>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
    int flag[12];
    int a[12];
    void dfs(ll left,ll n){
    	if(left==n){
    		for(int i=0;i<left;i++){
    			cout<<a[i]<<" ";
    		}
    		cout<<endl;
    		return ;
    	}
    	for(ll i=1;i<=n;i++){
    		if(!flag[i]){
    			flag[i]=1;
    			a[left]=i;//这里不能直接输出i,因为dfs搜索时每条路径不会重复,所以前面已经搜出来的不会再进行打印 
    			dfs(left+1,n);
    			flag[i]=0;
    		}
    	}
    	return ;
    } 
    
    int main(){
    	ll n;
    	cin>>n;
    	dfs(0,n);
    	return 0;
    }
    //            /       |  /  |**、
    //			 /        | /   |   
    //			/         |/    |   /  _____                      ____   |  /
    //		   /------    |    |__/  /             /      /  /      | /
    //		  /           |    |    /             /      /  /______ |/
    //		 /            |    |           /     /      /           |
    //      /             |    |     \_____/     /      /     \_____  |
    /**
     *        ┏┓    ┏┓
     *        ┏┛┗━━━━━━━┛┗━━━┓
     *        ┃       ┃  
     *        ┃   ━    ┃
     *        ┃ >   < ┃
     *        ┃       ┃
     *        ┃... ⌒ ...  ┃
     *        ┃       ┃
     *        ┗━┓   ┏━┛
     *          ┃   ┃ Code is far away from bug with the animal protecting          
     *          ┃   ┃   神兽保佑,代码无bug
     *          ┃   ┃           
     *          ┃   ┃        
     *          ┃   ┃
     *          ┃   ┃           
     *          ┃   ┗━━━┓
     *          ┃       ┣┓
     *          ┃       ┏┛
     *          ┗┓┓┏━┳┓┏┛
     *           ┃┫┫ ┃┫┫
     *           ┗┻┛ ┗┻┛
     */
    // warm heart, wagging tail,and a smile just for you!
    //
    //                            _ooOoo_
    //                           o8888888o
    //                           88" . "88
    //                           (| -_- |)
    //                           O  =  /O
    //                        ____/`---'\____
    //                      .'  |     |//  `.
    //                     /  |||  :  |||//  
    //                    /  _||||| -:- |||||-  
    //                    |   | \  -  /// |   |
    //                    | \_|  ''---/''  |   |
    //                      .-\__  `-`  ___/-. /
    //                  ___`. .'  /--.--  `. . __
    //               ."" '<  `.___\_<|>_/___.'  >'"".
    //              | | :  `- \`.;` _ /`;.`/ - ` : | |
    //                 `-.   \_ __ /__ _/   .-` /  /
    //         ======`-.____`-.___\_____/___.-`____.-'======
    //                            `=---='
    //        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    //
    

      

  • 相关阅读:
    腰围2尺1,2,3,4,5,6,7,8寸各自等于是多少厘米/英寸(对比表)
    Android开发模板------自己定义SimpleCursorAdapter的使用
    怎样在多线程中使用JNI?
    UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)
    图解iPhone开发新手教程
    Why Hadoop2
    读完了csapp(中文名:深入理解计算机系统)
    hadoop备战:一台x86计算机搭建hadoop的全分布式集群
    Win7 公布网站 HTTP 错误 404.4
    Dump 文件生成与分析
  • 原文地址:https://www.cnblogs.com/akpower/p/11773925.html
Copyright © 2020-2023  润新知