标签:
Description
Input
Output
Sample Input
100 2
Sample Output
68
Hint
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int ans; int mv[25],ms[25]; int n,m; const int inf=0xffffff; void dfs(int cur,int r,int h,int s_now,int v_now) { if(cur==0) { if(v_now==n) ans=min(s_now,ans); return; } if(s_now+ms[cur-1]>=ans||v_now+mv[cur-1]>n||2*(n-v_now)/r+s_now>=ans) return; for(int i=r;i>=cur;i--) { if(cur==m) s_now=i*i;//上表面的面积等于最底层的蛋糕的圆面积 for(int j=h;j>=cur;j--) { dfs(cur-1,i-1,j-1,s_now+2*i*j,v_now+i*i*j); } } } int main() { mv[0]=ms[0]=0; for(int i=1;i<=20;i++) { mv[i]=mv[i-1]+i*i*i; ms[i]=ms[i-1]+2*i*i; } while(scanf("%d%d",&n,&m)!=EOF) { ans=inf; dfs(m,(int)sqrt(n),n,0,0); if(ans==inf) cout<<0<<endl; else cout<<ans<<endl; } }
标签:
原文地址:http://www.cnblogs.com/xuejianye/p/5658350.html