康托展开 未完成

#include<iostream>
#include<algorithm>
#include<cstring>
typedef unsigned long long  ull;
using namespace std;
const int N = 1000002;
long fac[]={1,1,2,6,24,120,720,5040,40320,362820};
int n,a[N];
int cantor(int str[],int n){
    ull res=0;
    for (int i = 0; i < n; i++) {
        int cot=0;
        for (int j = i+1; j < n; j++) {
            if(str[i]>str[j]) cot++;
        }
        res+=cot*fac[n-i-1];
    }
    return (res+1)%998244353;
}
int main(){

    ios::sync_with_stdio(false);
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin>>a[i];
    }
    cout<<cantor(a,n)<<endl;
    return 0;
}

 

posted @ 2021-05-15 22:06  limited_Infinite  阅读(50)  评论(0编辑  收藏  举报
// //返回顶部 //返回顶部按钮