看题解看到了Russ的分数加成法,优先dfs左边,回溯输出,再dfs右边。。。。。。。
code:
/*
ID: yueqiq
LANG: C++
TASK: frac1
*/
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define ls rt<<1
#define rs rt<<1|1
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("frac1.in","r",stdin)
#define writef freopen("frac1.out","w",stdout)
const double pi = acos(-1.0);
const int maxn = 50;
const int BigP = 99999999;
const int INF = 99999999;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
using namespace std;
int N,ans;
//a1/b1第一个分数 a2/b2第二个分数
void dfs(int a1,int b1,int a2,int b2){
if(a1+a2>N||b1+b2>N) return ;
int m1=a1+a2,m2=b1+b2;
dfs(a1,b1,m1,m2);
printf("%d/%d\n",m1,m2);
dfs(m1,m2,a2,b2);
}
int main(){
readf;
writef;
SD(N);
puts("0/1");
dfs(0,1,1,1);
puts("1/1");
return 0;
}