POJ-1190 Birthday Cake NOI99

Source: Internet
Author: User

Deep Search + several pruning.

Looks like the search order is also very important ... I don't know if it's because of this and the tle has been a long time ...

#include <cstdio>#include<iostream>#include<fstream>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<queue>#defineRep (I, L, R) for (int i=l; i<=r; i++)#defineDown (i, L, R) for (int i=l; i>=r; i--)#defineMAXN 23#defineMAX 1<<30using namespacestd;intN, M, ans, MINV[MAXN], MINS[MAXN];voidSearch (intVintSintLintRintH) {    if(!l) {if(v = = N && s <ans) ans=s; return; }    if(s+mins[l-1] >= ans | | v+minv[l-1] > N | | (N-V) *2>= r* (ans-s))return; Down (R, R-1, L) {        if(L = = m) s = r*R; inttmp = MIN ((n-v-minv[l-1])/(R*R), H1); Down (H, TMP, L) Search (v+r*r*h, S+2*r*h, L1, R, h); }}intMain () {scanf ("%d%d", &n, &m); Ans = n+1; Rep (I,1, m) minv[i] = minv[i-1]+i*i*i; Rep (I,1, m) mins[i] = mins[i-1]+2*i*i; Search (0,0, M, sqrt ((Double) (n-minv[m-1])/m) +1, (n-minv[m-1])/(M*M) +1); if(ans = = n+1) ans =0; printf"%d\n", ans); return 0;}
View Code

POJ-1190 Birthday Cake NOI99

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.