题目来源:https://www.acwing.com/problem/content/1362/
思路分析
例如:0/1和1/1中间可以生成(0 + 1)/(1 + 1) = 1/2
然后0/1和1/2中间可以生成(0 + 1)/ (1 + 2) = 1/3
1/2和1/1中间可以生成(1 + 1) / (2 + 1) = 2/3
以上和以下都是SB Tree的具体做法
代码
//枚举两遍即可
#include<iostream>
#include<algorithm>
using namespace std;
int n;
//我们可以通过a/b和c/d,生成(a+c)/(b+d)
void dfs(int a,int b,int c,int d){
if(b+d>n)return;
dfs(a,b,a+c,b+d);
cout<<a+c<<"/"<<b+d<<endl;
dfs(a+c,b+d,c,d);
}
int main(){
cin>>n;
puts("0/1");
dfs(0,1,1,1);
puts("1/1");//前后这两个都是固定的
return 0;
}