比赛 期末考试3 评测结果 WWWWWWWWWWWWWWWWWWWW
题目名称 hope I can sort 最终得分 0
用户昵称 zhyn 运行时间 0.057 s
代码语言 C++ 内存使用 4.04 MiB
提交时间 2026-02-11 12:16:21
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 5000
int n,m;
int num[maxn];
const ll mod=998244353;
ll sum=0,ans=0;

ll mode(ll x){
	if(x>mod){
		x-=mod;
	}
	return x;
}


ll qpow(ll a,ll b) {
    ll res=1;
    a%=mod;
    while (b) {
        if (b&1) res= res*a %mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

ll get_inv(ll x) {
    return qpow(x,mod-2);
}

bool check(){
	for(int i=2;i<=n;i++){
		if(num[i]<num[i-1]){
			return false;
		}
	}
	return true;
}

void dfs(int x){
	if(x>m){
		if(check()){
			sum++;
			sum=mode(sum);
		}
		ans++;
		ans=mode(ans);
		return;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(num[i]>num[j]){
				swap(num[i],num[j]);
				dfs(x+1);
				swap(num[i],num[j]);
			}
			dfs(x+1);
		}
	}
}

int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	
	freopen("hopeicansort.in ","r",stdin);
	freopen("hopeicansort.out","w",stdout);
	
	cin>>n>>m;
	
	for(int i=1;i<=n;i++){
		cin>>num[i];
	}
	
	dfs(1);
	ll res=sum*get_inv(ans)%mod;
	res%=mod;
	cout<<res;
	
	
	return 0;
}