LOJ#10022. 埃及分数【搜索+剪枝】

本文探讨LOJ#10022埃及分数问题,重点在于搜索算法与剪枝技巧的应用。由于对最大公约数(gcd)的错误处理,导致解题延误。通过迭代加深搜索来枚举所有可能的分数解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述 https://loj.ac/problem/10022
这是一个因gcd打错而耽误的题。
这个题要枚举的是有多少个分数,迭代加深搜索!!

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll a,b,c[210000],sg[210000];
int maxn,tt=99999;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
ll mi(ll a,ll b)
{
	for(int i=2;;i++)
	  if(b<=a*i) return i;
}
bool jud(int dp)
{
	if(maxn>tt) return 0;
	if(sg[maxn]>c[tt]) return 0;
	return 1;
}
bool dfs(int d,ll minx,ll x,ll y)//层数 最小层数 分子 分母 
{
	if(d==maxn) 
	{
		if(y%x!=0) return 0;
		sg[d]=y/x;//商
		if(jud(d))
		{
			for(int i=1;i<=maxn;i++) c[i]=sg[i];
			tt=maxn;
		}
		return 1;
	}
	minx=max(minx,mi(x,y));
	bool  fl=0;
	for(int i=minx;i;i++)
	{
		if((maxn-d+1)*y<=i*x) break;
		sg[d]=i;
		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值