首页 > 其他 > 详细

康托展开 未完成

时间:2021-05-16 01:11:13      阅读:15      评论:0      收藏:0      [点我收藏+]
#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;
}

 

康托展开 未完成

原文:https://www.cnblogs.com/limitedInfinite/p/14772702.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!