千和


私信TA

用户名:wyt23333

访问量:980

签 名:

就算想法幼稚短浅也不能忘记前进

等  级
排  名 10120
经  验 1048
参赛次数 0
文章发表 6
年  龄 0
在职情况 学生
学  校 东华理工大学
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<bits/stdc++.h>
using namespace std;
map<char,int>m;         //对排列中的字符进行查重
set<string>Set_;        //对字符串排列进行查重
string s="";
int ans=0;
int num;
    void dfs(int index){
        if(index>=num&&Set_.count(s)==0){
            Set_.insert(s);
            //cout<<s<<endl;
            ans++;
            return;
        }
        for(auto i=m.begin();i!=m.end();i++){    //对map中出现过的字符进行遍历
            if(i->second<=0){                    //如果字符出现次数为0,跳过这次循环
                continue;
            }
            s+=i->first;
            i->second--;                         //将字符出现的次数减去1
            dfs(index+1);                        //进入下一层搜索
            s.erase(s.length()-1);               //删除叶子节点元素
            i->second++;
        }
    }
main(){
    string temp;
    cin>>num;
    cin>>temp;
    for(int i=0;i<num;i++){
        m[temp[i]]++;                            //用map统计字符
    }
    dfs(0);
    cout<<ans;
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区