zoukankan      html  css  js  c++  java
  • [搜索] [洛谷] P1691 有重复元素的排列问题

    搜索 OR next_permutation(arr, arr + len);

    //#pragma GCC optimize(2)
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <ctime>
    #include <vector>
    #include <fstream>
    #include <list>
    #include <iomanip>
    #include <numeric>
    using namespace std;
    typedef long long ll;
    
    const int MAXN = 1e6 + 10;
    
    int times[27] = {0}, ans = 0, len;
    
    int arr[MAXN] = {0};
    
    void dfs(int step)
    {
        if(step == len)
        {
            ans++;
    
            for(int i = 0; i < len; i++)
                cout<<char(arr[i] + 'a');
            cout<<endl;
            return ;
        }
        else
        {
            for(int i = 0; i < 26; i++)
            {
                if(times[i] > 0)
                {
                    arr[step] = i;
                    times[i]--;
                    dfs(step + 1);
                    times[i]++;
                }
                
            }
        }
    }
    
    int main()
    {
        //ios::sync_with_stdio(false);
    
        //cin.tie(0);     cout.tie(0);
    
        cin>>len;
    
        char a;
    
        for(int i = 0; i < len; i++)
        {
            cin>>a;
            times[a - 'a']++;
        }
    
        dfs(0);
    
        cout<<ans<<endl;
    
        return 0;
    }
  • 相关阅读:
    BPF and eBPF linux
    o-sync-and-o-direct
    linux performance test
    iostat
    MYSQL IO innodb-buffer-pool
    MYSQL file types redo log
    read pread write pwrite open
    CORE DUMP
    linux kernel的中断子系统 softirq
    linux KERNEL 问题
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270440.html
Copyright © 2011-2022 走看看