Poj1190 birthday cake dfs

Source: Internet
Author: User

 


The birthday cake has m layers and the total volume is V. From bottom up, the radius r and height h of each layer are decreasing.

For m and v, obtain the smallest surface area s. (Not counted from the ground area on the bottom)

Link: poj1190

 


Pruning is not yet added .. The output in the sample is all incorrect... No problem found...

 

# Include <iostream> # include <cstring> # include <string> # include <cstdio> # include <cmath> # include <algorithm> # include <vector> # include <map> # define inf 0x3f3f3fusing namespace std; int ans, V, M, flag, s; int dfs (int v, int m, int newr, int newh) {int r, h, tmp, I; if (m = 0) {flag = 1; if (v = 0 & s <ans) ans = s; return 0 ;}for (I = 1, tmp = 0; I <= m; I ++) // obtain the minimum tmp + = (I * I) for each layer. if (tmp> v) return 0; // if the value is greater than the remaining v, it is impossible to use tmp-=. (M * m); for (r = newr; r> = m; r --) {for (h = newh; h> = m; h --) {// for (I = 0, tmp = 0; I <m; I ++) // The maximum value is obtained for each layer. // This pruning is also affected. // tmp + = (r-I) * (h-I ); // if (v> tmp) break; // It is neither possible if (m = M) s + = r * (2 * h + r) if it is still smaller than v ); else s + = 2 * r * (h + r); if (s <ans) dfs (v-(r * h), S-1, R-1, h-1); if (m = M) s-= r * (2 * h + r); else s-= 2 * r * (h + r );}} return 0;} int main () {while (~ Scanf ("% d", & V, & M) {ans = inf; s = 0; flag = 0; dfs (V, M, 1000,1000 ); printf ("% d \ n", flag? Ans: 0);} return 0 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.