90分求调
查看原帖
90分求调
881317
spessert楼主2024/3/26 20:18

第五个测试点错了

#include<bits/stdc++.h>
using namespace std;
int n,k;
int x[25];  //x[1]=2代表第1层的数字是2,共k层
bool check(int a){  //判断数字个数是否达到k个
	if(a>k){
		for(int i=1;i<=k;i++){
			cout<<setw(3)<<x[i];
		}
		cout<<endl;
		return true;
	}
	return false;
}
bool bd(int a){  //判断该层的数字是否合法
	if((a==n)||(x[a]<=x[a-1])){  
		return false;
	}else{
		return true;
	}
}
void DFS(int a){
	
	if(check(a)){
		return ;
	}
	
	for(int i=1;i<=n;i++){
		x[a]=i;
		if(bd(a)){
			DFS(a+1);
		}else{
			continue;
		}
	}
}
int main(){
	cin>>n>>k;
	DFS(1);
	
	return 0;
}
2024/3/26 20:18
加载中...