Luo Gu P1731 [NOI1999] birthday cake explanations

Daily questions day53 punch

Analysis

Observation of the cake a plan view, the upper surface area of ​​the fact that the bottom layer of the bottom area, the bottom area when the addition of the first search, then it is only considered Jiuhaola side area.

Is the time to enumerate the r and h, how to select the upper and lower bounds of it?

The height of a layer referred to as LH, a layer referred to as a radius LR, it is judged good upper bound islh-1 and L R & lt - . 1 ,

The bottom should be selected at 20,000 cubic rootRange of about 28

Now consider the lower bound:

T 1 will naturally choose a miserable, The lower bound is the minimum thing, the top layer ofand rh is the minimum1 ah, that there are several layers lower bound is a few friends!

ThenhappyTo prune:

Compare miss pruning are two:

  1. When the answer to the sum of the areas before the current has been exceeded, R & lt E T U R & lt n-

  2. When the volume exceeds the volume of the current requirements, R & lt E T U R & lt n-

There are some pruning, difficulty thinking is not too high:

  • When now has the largest volume of plus(Not a true maximum, will be bigger than the maximum number)When the body is also less than the required volume, R & lt E T U R & lt n-

  • Once the area has been coupled with the current minimum(Naturally, this is smaller than the smallest real number)Area ratio has the answer bigger, r E t U r the n-

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define int long long
 6 #define INF 2147483647
 7 #define rep(i,s,e) for(register int i=s;i<=e;++i)
 8 #define dwn(i,s,e) for(register int i=s;i>=e;--i)
 9 using namespace std;
10 inline int read()
11 {
12     int x=0,f=1;
13     char c=getchar();
14     while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();}
15     while(c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
16     return f*x;
17 }
18 inline void write(int x)
19 {
20     if(x<0) {putchar('-'); x=-x;}
21     if(x>9) write(x/10);
22     putchar(x%10+'0');
23 }
24 int n,m,ans=INF;
25 void dfs(int layer,int volume,int area,int radius,int height)
26 {
27     if(area>=ans) return;
28     if(layer==m+1&&volume==n)
29     {
30         ans=min(ans,area);
31         return;
32     }
33     if(volume>=n) return;
34     int now_layer=m-layer+1;
35     if(volume+now_layer*radius*radius*height<n) return;
36     if(area+now_layer*2>ans) return;
37     if(layer==1)
38     {
39         rep(r,m,radius)
40             rep(h,m,height)
41                 dfs(layer+1,volume+r*r*h,area+2*r*h+r*r,r,h);
42     }
43     else 
44     {
45         rep(r,now_layer,radius-1)
46             rep(h,now_layer,height-1)
47                 dfs(layer+1,volume+r*r*h,area+2*r*h,r,h);
48     }
49 }
50 signed main()
51 {
52     n=read();m=read();
53     dfs(1,0,0,28,28);
54     if(ans==INF) write(0);
55     else write(ans);
56     return 0;
57 }

Please Gangster treatise(Anyway, I do not know what that means treatise)

Guess you like

Origin www.cnblogs.com/handsome-zyc/p/11972192.html