This commit is contained in:
e2hang
2025-09-11 15:53:33 +08:00
parent 6839d2ea13
commit 265b8af720
7 changed files with 384 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
// f = a/b
double checkv(const vector<int>& x){
double c = 0.0;
for(auto q : x){
c += 1.0 / q;
}
return c;
//return fabs(c - r) < 1e-9; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƱȽ<C6B1>
}
//<2F><>step<65><70>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
bool dfs(vector<int>& path, int step, int max_depth, int a, int b, int max_val){
double r = static_cast<double>(a) / b;
if(fabs(checkv(path) - r) < (1e-9)){
for(int x : path) cout << x << " ";
cout << endl;
return true;
}
if(checkv(path) > r + (1e-9)) return false;
if(step == max_depth) return false;
int start = path.empty() ? 1 : path.back();
for(int i = start; i <= max_val; i++){
path.push_back(i);
if(dfs(path, step + 1, max_depth, a, b, max_val)) return true;
path.pop_back();
}
return false;
}
bool ids(int limit, int a, int b, int max_val){
for(int depth = 1; depth <= limit; depth++){
vector<int> path;
if(dfs(path, 0, depth, a, b, max_val)) return true;
}
return false;
}
int main(){
int aa, bb, max;
cin >> aa >> bb;
max = 200;
ids(10, aa, bb, max);
return 0;
}