6 条题解

  • 5
    @ 2026-2-12 11:07:08

    STL模版法:

    #include<bits/stdc++.h>
    using namespace std;
    int n;
    int a[11]={0,1,2,3,4,5,6,7,8,9};
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cin>>n;
    	do{
    		for(int i=1;i<=n;i++){
    			cout<<setw(5)<<a[i];
    		}
    		cout<<"\n";
    	}while(next_permutation(a+1,a+n+1));
    	return 0;
    }
    
    • @ 2026-2-12 11:09:33

      这是全排列模版:

      next_permutation(a+1,a+n+1)

  • 0
    @ 2026-2-13 10:14:38
    #include <bits/stdc++.h>
    using namespace std;
    int n;
    vector<int> path;
    bool used[10];   // n<=9
    void dfs() {
        // 终止条件:已经选了 n 个数
        if (path.size() == n) {
            for (int i = 0; i < n; i++) {
                cout << path[i] << " ";
            }
            cout << endl;
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (!used[i]) {
                used[i] = true;       // 1. 标记使用
                path.push_back(i);    // 2. 做选择
                dfs();                // 3. 递归
                path.pop_back();      // 4. 撤销选择
                used[i] = false;      // 5. 取消标记
            }
        }
    }
    int main() {
        cin >> n;
        dfs();
        return 0;
    }
    
    
    
    • -2
      @ 2026-2-12 10:59:16
      #include<bits/stdc++.h>
      using namespace std;
      int n;
      vector <int>a;
      bool b[1001];
      void s(){
      	if(a.size()==n){
      		for(int i=0;i<a.size();i++){
      			cout<<setw(5)<<a[i];
      		}
      		cout<<"\n";
      		return ;
      	}
      	for (int i=1;i<=n;i++) {
      		if(b[i]){
      			a.push_back(i); 
      			b[i]=false;   
      			s();      
      			b[i]=true;         
      			a.pop_back();
      		}     
          }
      }
      int main() {
      	ios::sync_with_stdio(false);
      	cin.tie(0);
      	cin>>n;
      	for(int i=1;i<=n;i++){
      		b[i]=true;
      	}
      	s();
          return 0;
      }
      
      
      

      求大佬修改

      • -3
        @ 2026-2-12 11:28:04
        /)otir!jk\hozy?yzji;;>n^£!yotm¥tgskyvgik¥yzj[£otz¥t[£"kizux\otz^¥vgzn[£huur¥!ykj{77}[£"uoj¥jly./¥
        £¥¥¥¥ol.vgzn>yo&k./]]t/¥
        £¥¥¥¥¥¥¥¥lux.otz¥o]6[o\t[o;;/¥
        £¥¥¥¥¥¥¥¥¥¥¥¥iu!z\\ykz#.B/\\vgzn{o}[£¥¥¥¥¥¥¥¥·£¥¥¥¥¥¥¥¥iu!z\\ktjr[£¥¥¥¥¥¥¥¥xkz!xt[£¥¥¥¥·££¥¥¥¥lux.otz¥o]7[o\]t[o;;/¥
        £¥¥¥¥¥¥¥¥ol.'!ykj{o}/¥
        £¥¥¥¥¥¥¥¥¥¥¥¥!ykj{o}]zx!k[£¥¥¥¥¥¥¥¥¥¥¥¥vgzn>v!yn hgiq.o/[£¥¥¥¥¥¥¥¥¥¥¥¥jly./[£¥¥¥¥¥¥¥¥¥¥¥¥vgzn>vuv hgiq./[£¥¥¥¥¥¥¥¥¥¥¥¥!ykj{o}]lgryk[£¥¥¥¥¥¥¥¥·£¥¥¥¥·£·£otz¥sgot./¥
        £¥¥¥¥iot^^t[£¥¥¥¥jly./[£¥¥¥¥xkz!xt¥6[£·£\
        

        偏移量:1203334

        解密器

        • -3
          @ 2026-2-12 11:12:48
          /oUZOXgPQ$NUfe!efPOwwzT&?geUZS=ZMYQebMOQ=efP#?UZf=Z#?hQOfad=$UZf&M#?NaaX=N) ̄〓〓 ̄+#?haUP=etu/?@URtMzeUlQtu%%Zu/?@@RadtUZf=U%〓#U$MzeUlQtu#Uwwu/?@@@Oagf$$eQfit々u$$M)U+#?@@;?@@Oagf$$n*Zn#?@@dQfgdZ=#?@;?@Rad=tUZf=U% ̄#U$%Z#Uwwu=/?@@URtN)U+u/?@@@MzbgeT-NMOWtUu#=?@@@N)U+%RMXeQ#===?@@@etu#======?@@@N)U+%fdgQ#=========?@@@Mzbab-NMOWtu#?@@;=====?====;?;?UZf=YMUZtu=/?@Uae""ekZO-iUfT-efPUatRMXeQu#?@OUZzfUQt〓u#?@OUZ&&Z#?@RadtUZf=U% ̄#U$%Z#Uwwu/?@@N)U+%fdgQ#?@;?@etu#?====dQfgdZ=〓#?;\
          
          • -5
            @ 2026-2-12 11:07:38

            /oUZOXgPQNUfe!efPOwwzT&?geUZS=ZMYQebMOQ=efP#?UZf=Z#?hQOfad=UZf&M#?NaaX=N) ̄〓〓 ̄+#?haUP=etu/?@URtMzeUlQtu%%Zu/?@@RadtUZf=U%〓#UMzeUlQtu#Uwwu/?@@@OagfeQfitueQfit々uM)U+#?@@;?@@Oagfn*Zn#?@@dQfgdZ=#?@;?@Rad=tUZf=U% ̄#U%Z#Uwwu=/?@@URtN)U+u/?@@@MzbgeT-NMOWtUu#=?@@@N)U+%RMXeQ#=?@@@etu#?@@@N)U+%fdgQ#=?@@@Mzbab-NMOWtu#?@@;=?====;?;?UZf=YMUZtu=/?@Uae""ekZO-iUfT-efPUatRMXeQu#?@OUZzfUQt〓u#?@OUZ&&Z#?@RadtUZf=U% ̄#U$%Z#Uwwu/?@@N)U+%fdgQ#?@;?@etu#?====dQfgdZ=〓#?;?\

          • 1

          信息

          ID
          86
          时间
          1000ms
          内存
          256MiB
          难度
          3
          标签
          递交数
          37
          已通过
          24
          上传者