Http://poj.org/problem? Id = 1190

Source: Internet
Author: User

/* This is an enumeration search of the radius and height, however, pruning is required */# include <iostream> # include <cmath> # include <cstdio> # include <algorithm> using namespace std; int n, m, minv [21], mins [21], best; void dfs (int M, int v, int s, int r, int h) {int I, j, hmax; if (M = 0) {if (v = n & s <best) best = s; return ;} if (v + minv [M]> n | s + mins [M]> = best | 2 * (n-v)/r + s> = best) return; // trim the current volume and the minimum volume of the remaining M layer is greater than n // The lateral area and the Minimum side area of the remaining M layer are greater than or equal to the best/* The side area of the remaining M layer is lefts = 2 * (r [k] * h [k] +... + r [m] * h [m]), k = (M + 1 ,.., m) lefts> 2 * (n-v)/r; lefts = best-s; */for (I = R-1; I> = M; I --) {if (M = m) s = I * I; hmax = min (n-v)/(I * I), h-1); for (j = hmax; j> = M; j --) dfs (M-1, v + I * j, s + 2 * I * j, I, j );}} int main (int argc, char * argv []) {int I, rmax, hmax; minv [0] = 0; mins [0] = 0; for (I = 1; I <21; I ++) mins [I] = mins [I-1] + 2 * I, minv [I] = minv [I-1] + I * I; // array mins, minv records the minimum area and volume of the layer, obtained when I is equal to; while (cin> n> m) {rmax = sqrt (1.0 * n) + 1; hmax = n/(m * m) + 1; best = 1000000; dfs (m, rmax, hmax ); if (best = 1000000) best = 0; cout <best <endl;} 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.