Deep search has been mentioned, for pruning is to carry out the necessary steps if no special pruning sentence, with good complexity can greatly optimize
According to two examples here in terms of it
1440: division [1] number of examples
For details, see the code
#include <cstdio> #include <CString> #include <algorithm> int n-, K; int F [ 210 ] [ . 7 ]; int main () { Scanf ( " % D% D " , & n-, & K); Memset (F, 0 , the sizeof (F)); // F is initialized array 0, F [ 0 ] [ 0 ] = 1 ; // but the first to 1, in order to prevent Calais are added to 0 for ( int I = . 1 ; I <= n-; I ++) // sum cycle for (int j = I; j <= n-; j ++) // is the sum of the cycle, as has already been cycled i, j may thus directly start I // two cycles later to pave the way for the state of the processing for ( int X = . 1 ; X <= K; X ++) // this is the number of cycles of the program { F [J] [X] = F [J] [X] + F [JI] [X- . 1 ]; // F [J] [x] is the maximum value of the total number of programs @ JI is to prevent repeated, for example: 1 1 1 1 1,5 5,1 5 this happens // is a maximum value of x-1, in order to inherit a } the printf ( " % D \ n- " , F [n-] [K]); // output maximum return 0 ; }
1441: example [2] birthday cake
For details, see the code
include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<vector> #include<map> #include<string> #include<cstring> using namespace std; const int maxn=0x3f3f3f3f; const int minn=-0x3f3f3f3f; int n,m,ans,a[10086],b[10086]; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x *F; } / * Volume V = πR2H side area A = 2πRH bottom area πR2 = A * / void DFS ( int V / * Used by volume * / , int S / * surface area * / , int P / * remaining layers Note residual * / , int R & lt / * radius * / , int H / * high * / ) { IF (P == 0 ) { // If no remaining layers has been found the search, then no! IF (V n-S && == < ANS) ANS =S; return ; } IF (V + B [p- . 1 ]> n) return ; // ! add if the volume is greater than the maximum volume of this layer is further found that the n ass IF (A + S [p- . 1 ]> ANS) return ; IF ( 2 * (NV) / R & lt S +> = ANS) return ; // current surface area of the remaining lateral area +> further found that this optimum value ass! for ( int I = R- . 1 ; I> = P; i--) { // radius IF (P == m) S = I * I; int pyyyyyy = min ((NVB [p-1])/(i*i),h-1); for(int j=pyyyyyy; j>=p; j--) //高 dfs(v+i*i*j,s+2*i*j,p-1,i,j); } } int main() { n=read(); m=read(); cin>>n>>m; ans=maxn; a[0]=0; b[0]=0; for(int i=1; i<21; i++) { A [i] = A [I- . 1 ] + 2 * i * i; // maximum surface area layer i B [i] = B [I- . 1 ] + i * i * i; // i layer volume = πR2H maximum volume V } DFS ( 0 , 0 , m, n-+ . 1 , n-+ . 1 ); // search @ 5 mean the amount of fancy IF (ANS == MAXN) COUT << 0 ; the else COUT < < ANS; return 0 ; }