This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>
usingnamespacestd;
// 阶乘表
intfact[20];
voidinit_fact(intn){
fact[0]=1;// 0的阶乘为1
for(inti=1;i<=n;i++)fact[i]=fact[i-1]*i;
}
// 康托展开
intcantor(stringstr){
intx=1;// 注意,因为 12345 是算作0开始计算的,最后结果要把12345看作是第一个
intlen=str.size();
for(inti=0;i<len;i++){
intsmaller=0;// 在当前位之后小于其的个数
for(intj=i+1;j<len;j++)
if(str[i]>str[j])smaller++;
// 两种方法:
// ① 往后看,计算str[i]是第几大的数,或者说计算有几个比他小的数
// ② 往前看,计算出现了几个比自己小的数,从自己身上扣除掉逆序数量,也就是后面剩余比自己小的数量