Solution to a problem P1731 [[NOI1999]] birthday cake - Los Valley

This problem came up with their own chiefs% Konjac here you have

I was too weak,This spicy chicken search algorithm will not(escape

This question is really like a long time, every time T three points, I thought my pruning has piled more than enough, and then I was the result of a key pruning did not expect OTZ

First posted Code

#include <bits/stdc++.h>
using namespace std;
#define rint register int 
int n, m, ans = 99999999;
int ini1[20], ini2[20];
inline void init( void ){
    for( rint i = 1; i <= m; i++ ){
        ini1[i] = pow( i, 3 ) + ini1[i - 1];
        ini2[i] = 2 * i * i + ini2[i - 1]; 
    }
    return ;
}
inline void dfs( int nowv, int nows, int r, int h, int t ){
    if( t == 0 ){
        if( nows == n ) ans = min( ans, nowv );
        return ;
        //cout << 1;
    }
    if( nowv + ini2[t - 1] >= ans ) return ;
    //cout << 1;
    if( nows + ini1[t - 1] >= n ) return;
    //cout << 1;
    if( 2 * ( n - nows ) / r + nowv >= ans ) return ;
    for( rint i = r - 1; i >= t; i-- ){
        //cout << 1;
        if( t == m ) nowv = i * i;
        int hh = min( h - 1, ( n - nows - ini1[t - 1] ) / ( i * i ) );
        for( rint j = hh; j >= t; j-- ){
            //cout << t << endl;
            dfs( nowv + 2 * i * j, nows + i * i * j, i, j, t - 1 );
        }
    }
    return ;
}
int main( void ){
    scanf( "%d%d", &n, &m );
    init();
    int temp = sqrt( n );
    //for( int i = 1; i <= m; i++ ) cout << ini[i] << ' ';
    dfs( 0, 0, temp + 1, n + 1, m );
    if( ans == 99999999 ){
        cout << 0;
        return 0;
    }
    cout << ans;
    return 0;
}

Look at the output of 1 to know how many times I was wrong and found the play into a t \ (t - 1 \) qwq

Key pruning

if( 2 * ( n - nows ) / r + nowv >= ans ) return ;

Details push here

1 to $ dep - 1 $ volume of

\(n - v = \sum_{k = 1}^{dep - 1}h[k] * r[k] ^ 2\)

Surface area of

$2\sum_{k = 1}^{dep - 1}h[k] *r[k] $

Long and stinking warning

\ (\ because2 \ sum_ {k = 1} ^ {dep - 1} h [k] * r [k] = \ frac {2} {r [dep]} * \ sum_ {k = 1} ^ {dep - 1} h [k] * r [k] * r [dep] \ geqslant \ frac {2} {r [dep]} * \ sum_ {k = 1} ^ {dep - 1} h [k] * r [ K] ^ 2 \ geqslant \ FRAC {2 (n-- V)} {R & lt [DEP]} \)
\ (\ THEREFORE \) when $ \ frac {2 (n - v)} {r [dep]} + s \ Description geqslant ans $ is not optimal, you can return

This is the former \ (dep - 1 \) estimates layer side of the area, many people ignore this dimension, in fact, this dimension have in our pretreatment \ (the INI \)
(Do not get excited, \ (the init \) deleted go \ (t \) only when 23333) have been involved, but we are not too concerned about it

This tells us that all aspects must be considered in the design conditions when pruning
, each dimension has pondered, as far as possible to reach the upper and lower bounds

return 0;//功德圆满

Guess you like

Origin www.cnblogs.com/with6676/p/11517831.html