有没有大佬知道我这篇的时间复杂度啊,感觉时间复杂带度很大,但还是过了
#include<bits/stdc++.h>
using namespace std;
int n, m, k;
int a[10010], st[10010];
int ans = 0;
void dfs(int x){
if(x > n){
k ++;
if(k == m + 1){
for(int i = 1;i <= n;i ++) printf("%d ", a[i]);
printf("\n%d\n", ans);
exit(0);
}
return;
}
if(k == 0){
for(int i = a[x]; i <= n;i ++){
ans ++;
if(st[i]) continue;
st[i] = 1;
a[x] = i;
dfs(x + 1);
st[i] = 0;
}
}
else{
for(int i = 1;i <= n;i ++){
ans ++;
if(st[i]) continue;
st[i] = 1;
a[x] = i;
dfs(x + 1);
st[i] = 0;
}
}
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1;i <= n;i ++) scanf("%d", &a[i]);
dfs(1);
return 0;
}