2 条题解

  • 1
    @ 2022-7-29 20:09:36
    #include<bits/stdc++.h>
    using namespace std;
    long i,j,n,s;
    string b;
    char a[505];
    int main()
    {
    	cin>>n>>b;
    	for(i=1;i<=n;i++)a[i]=b[i-1];
        sort(a+1,a+n+1);
    	do{
    		for(i=1;i<=n;i++)cout<<a[i];
    		cout<<endl;s++;
    	}while(next_permutation(a+1,a+n+1));stl
    	cout<<s;
    	return 0;
    }
    • 1
      @ 2022-7-7 10:03:39

      大法师求解即可。

      #include <bits/stdc++.h>
      using namespace std;
      const int N = 155;
      int n, sum, cnt[N];
      vector<int> ans;
      char ch;
      void dfs(int depth) {
      	if (depth == n) {
      		for (char i : ans)
      			cout << i;
      		cout << '\n', sum ++;
      		return;
      	}
      	for (int i = 'a'; i <= 'z'; i ++)
      		if (cnt[i]) cnt[i] --, ans.push_back(i), dfs(depth + 1), ans.pop_back(), cnt[i] ++;
      }
      int main() {
      	cin >> n;
      	for (int i = 1; i <= n; i ++)
      		cin >> ch, cnt[ch] ++;
      	dfs(0);
      	cout << sum << '\n';
      	return 0;
      }
      
      • 1

      信息

      ID
      133
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      (无)
      递交数
      182
      已通过
      52
      上传者