救我
  • 板块灌水区
  • 楼主lyq17364950095
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/7/12 09:34
  • 上次更新2024/7/12 10:56:09
查看原帖
救我
1238068
lyq17364950095楼主2024/7/12 09:34

RE了!!!! P1219

using namespace std;
long long h[10001],l[10001],z[10001],y[10001];
int n;
int total;
int pt(){
	if(total<=2){
		for(int k=1;k<=n;k++){
			cout << h[k] << " ";
		}
		cout << endl;
	}
	total++;
}
void dfs(int i)
{
	if(i>n){
		pt();
		return ;
	}
	else{
	    for(int j=1;j<=n;j++){
		    if(!l[j]&&!z[i+j]&&!y[i-j+n]){
	            h[i]=j;
                l[j]=1;
                z[i+j]=1;
                y[i-j+n]=1;
		        dfs(i+1);
                l[j]=0;
                z[i+j]=0;
                y[i-j+n]=0;
			} 
	    }
	}
 }
 int main(){ 
    cin >> n;
    dfs(1);
    cout << total;
    return 0;
 }
2024/7/12 09:34
加载中...