为什么用我的dfs搜索会wa 10pts,求调,谢谢!
查看原帖
为什么用我的dfs搜索会wa 10pts,求调,谢谢!
765339
xiangby楼主2024/3/10 10:57
#include<bits/stdc++.h>
using namespace std;
int n;
vector<char>v;
int print(){
	for(int i=0;i<n;i++){
		cout<<v[i];
	}
	cout<<'\n';
}
void dfs(int now){
	if(now==n){
		print();
		return ;
	}
	v.push_back('O');
	dfs(now+1);
	v.pop_back();
	v.push_back('X');
	dfs(now+1);
	v.pop_back();
	
	return ;
}
int main(){
	cin>>n;
	
	dfs(0);
	for(int i=0;i<n;i++){
		cout<<'O';
	}
	cout<<'\n';
	return 0;
}

https://www.luogu.com.cn/record/150162550

2024/3/10 10:57
加载中...