#include <iostream>
using namespace std;
int ans = 0;
int N, M;
void dfs( int m, int leftV, int A, int lastR, int lastH)
{
if( m*(lastR-1)*(lastR-1)*(lastH-1) < leftV && m!=M) return; //剩余体积大于最大可能体积剪枝
if( leftV < 0) {return;}
if( ans && A > ans) return; // 当前面积比最小大剪枝
if( !m) {
if( !leftV && ( A < ans || !ans)) ans = A;
return;
}
for( int r = lastR - 1; r >= m; r--)
for( int h = lastH - 1; h >= m; h--){
int curV = r*r*h;
int curA = 2*r*h;
if( m == M) curA += r*r;
if( A+2*leftV/r > ans && ans) continue; // A+2*left/r > 当前面积加上剩下最小面积大于最小面积剪枝
dfs( m-1, leftV - curV, A+curA, r, h);
}
}
int main()
{
cin >> N >> M;
ans = 0;
dfs( M, N, 0, 100, 1000);
cout << ans << endl;
}
}
<
poj_ 1190 生日蛋糕
最新推荐文章于 2023-06-19 22:27:36 发布