到底是为什么??
查看原帖
到底是为什么??
816792
coritom楼主2024/7/26 18:09
#include <bits/stdc++.h>
using namespace std;
int n, k, a[10005], ans[10005], sum;
bool vis[100005];
void dfs(int x){
	if(x > n){
		sum++;
		if(sum == k + 1){
			for(int i = 1; i < x; i++) cout << ans[i] << " ";
			exit(0);
		}
		return ;
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]){
			ans[x] = a[i];
			vis[i] = 1;
			dfs(x + 1);
			vis[i] = 0;
		}
	}
}
signed main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0), cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	dfs(1);
	return 0;
}
此代码只有 30 分,求各位大佬帮忙看看,悬关!!
2024/7/26 18:09
加载中...