20pts 除#1#2外全蛙 求调玄关
查看原帖
20pts 除#1#2外全蛙 求调玄关
1771965
tuxiaolai楼主2025/7/29 17:34
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n;
string s;
int t[30];
int a[2100];
int cnt;
long long ans=1;
long long inv(int a,int t){
    long long res = 1;
    while(t){
        if(t&1)res=(long long)res*a%mod;
        a=(long long)a*a%mod;
        t>>=1;
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    a[0]=1;
    for(int i=1; i<=2100; i++) {
        a[i]=a[i-1]*i%mod;
    }
    cin>>n>>s;
    for(int i=1; i<=n; i++) {
        t[s[i-1]-'a']++;
    }
    //cout<<cnt;//c
    for(int i=0; i<26; i++) {
        //cout<<t[i]<<'\n';
        if(t[i]%2==1) {
            //cout<<"cnt:"<<cnt<<'\n';
            if(cnt==0) {
                cnt++;
                t[i]--;
            } else {
                cout<<a[n];
                return 0;
            }
        }
        if(t[i]) {
            ans=ans*a[t[i]]%mod*inv(a[t[i]/2],mod-2)%mod;
            //cout<<"ans:"<<ans<<'\n';//c
        }
    }
    cout<<a[n]-(ans*a[(n-cnt)/2]%mod);
    return 0;
}

注:只给代码的不关

2025/7/29 17:34
加载中...