5 条题解

  • 1
    @ 2025-7-18 10:55:51
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    const int N=1e2+10;
    string a;
    char box[N];
    bool v[N];
    int len;
    void dfs(int step){
    	if(step==len){
    		cout<<box<<endl;
    		return;
    	}
    	for(int i=0;i<len;i++){
    		if(v[i]==0){
    			box[step]=a[i];
    			v[i]=1;
    			dfs(step+1);
    			v[i]=0;
    		}
    	}
    }
    signed main(){
    	cin>>a;
    	len=a.size();
    	dfs(0);
    	return 0;
    }
    
    
    
    • 0
      @ 2025-7-18 10:55:48

      #include #include <string.h> #include <math.h> #include #include #include #include #include #include #include #include <stdio.h> #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include <complex.h> #include <fenv.h> #include <inttypes.h> #include <stdbool.h> #include <stdint.h> #include <tgmath.h> #define int long long using namespace std; const int N=1e6+10; string v; bool a[N]; char c[N]; int len; void dfs(int s) { if(s==len) { cout<<c<<endl; return ; } for(int i=0;i<len;i++) { if(a[i]==0) { c[s]=v[i]; a[i]=1; dfs(s+1); a[i]=0; } } } signed main() { cin>>v; len=v.size(); dfs(0); return 0; }

      • 0
        @ 2025-3-8 15:02:39

        我再来发一遍

        #include<bits/stdc++.h>
        using namespace std;
        const int N=1e5+5,INF=0x3f3f3f3f;
        typedef long long LL;
        string a;
        int main()
        {
        	cin>>a;
        	do{
        		cout<<a<<endl;
        	}while(next_permutation(a.begin(),a.end()));
        	return 0;
        }
        
        • 0
          @ 2025-1-29 21:08:34
          #include<bits/stdc++.h>
          using namespace std;
          int main(){
              string a;
              cin>>a;
              sort(a.begin(),a.end());
              do cout<<a<<endl;
              while (next_permutation(a.begin(), a.end()));
              return 0;
          }
          
          • @ 2025-1-29 21:09:35

            用sort和next_permutation就能实现全排列(STL函数真好用!)

        • -1
          @ 2024-11-10 19:49:12

          #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include <complex.h> #include <fenv.h> #include <inttypes.h> #include <stdbool.h> #include <stdint.h> #include <tgmath.h> #include <windows.h> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; char a[N] , box[N]; bool v[N]; int len; void dfs(int step){ if(step == len){ cout << box << endl; return; } for(int i = 0;i < len;i++){ if(!v[i]){ v[i] = 1; box[step] = a[i]; dfs(step + 1); v[i] = 0; } } } int main() { cin >> a; len = strlen(a); dfs(0); return 0; }

          • 1

          信息

          ID
          1239
          时间
          1000ms
          内存
          128MiB
          难度
          5
          标签
          递交数
          124
          已通过
          51
          上传者