社区讨论

20pts 除#1#2外全蛙 求调玄关

P5684[CSP-J 2019 江西] 非回文串参与者 3已保存回复 7

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
7 条
当前快照
1 份
快照标识符
@mdocebdr
此快照首次捕获于
2025/07/29 17:36
7 个月前
此快照最后确认于
2025/11/04 03:31
4 个月前
查看原帖
CPP
#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;
}
注:只给代码的不关

回复

7 条回复,欢迎继续交流。

正在加载回复...