# BZOJ 1024: [SCOI2009]生日快乐 dfs

### 题目链接:

http://www.lydsy.com/JudgeOnline/problem.php?id=1024

### 题解:

http://www.cnblogs.com/ljh2000-jump/p/6063364.html

dfs为什么取两种的最大值嘞 这两个是一个状态下的 一个产生 另一个就是必然

### 代码:

 1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 #define MS(a) memset(a,0,sizeof(a))
5 #define MP make_pair
6 #define PB push_back
7 const int INF = 0x3f3f3f3f;
8 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
10     ll x=0,f=1;char ch=getchar();
11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
13     return x*f;
14 }
15 //////////////////////////////////////////////////////////////////////////
16 const int maxn = 1e5+10;
17
18
19 double dfs(double x,double y,int num){  // 需要分成num块，且矩形长宽分别为x，y
20     if(num == 1){
21         return max(x,y)/min(x,y);
22     }
23
24     double ans1,ans2,ans=INF;
25     for(int i=1; i<=num/2; i++){ // 枚举横着或者竖着分成i份
26         double x1 = x/num, y1 = y/num;
27         ans1 = max(dfs(x1*i,y,i),dfs(x1*(num-i),y,num-i));
28         ans2 = max(dfs(x,y1*i,i),dfs(x,y1*(num-i),num-i));
29         ans = min(ans,min(ans1,ans2));
30     }
31     return ans;
32 }
33
34 int main(){
35     int x,y,n;
36     cin >> x >> y >> n;
37
38     printf("%.6lf\n",dfs(x,y,n));
39
40     return 0;
41 }

posted @ 2017-02-28 00:34  _yxg123  阅读(75)  评论(0编辑  收藏