*【bzoj 1024】生日快乐(DFS)

来源:互联网 发布:棕榈油 知乎 编辑:程序博客网 时间:2024/05/16 10:03

传送门biu~
n<=10,枚举所有情况。

#include<bits/stdc++.h>#define max(x,y) (x>y?x:y)#define min(x,y) (x<y?x:y)using namespace std;double dfs(double x,double y,int step){    double re=10000.0;    if(step==1) {        if(x<y)     return y/x;        else        return x/y;    }    double nx=x/step;    for(int i=1;i<step;++i){        double tmp=dfs(nx*i,y,i);        tmp=max(tmp,dfs(x-nx*i,y,step-i));        re=min(re,tmp);    }    double ny=y/step;    for(int i=1;i<step;++i){        double tmp=dfs(x,ny*i,i);        tmp=max(tmp,dfs(x,y-ny*i,step-i));        re=min(re,tmp);    }    return re;}int main(){    int x,y,n;    scanf("%d%d%d",&x,&y,&n);    printf("%.6lf",dfs(x,y,n));    return 0;}