### 四处错误
1. 第三行是 `0x3f3f3f3f`,您多了个 `3f`
2. 第十五行看不懂好像不对但没用,删了
3. 第二十四行应为 `lasth - 1`
4. 少了个剪枝,加上《算阶》上的最优性剪枝2就可以AC了
```cpp
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f //1.#define INF 0x3f3f3f3f3f
int v,m,ans,costv[20],costs[20];
int maxv(int r,int h,int cnt){
int sum=0;
for(int i=0;i<cnt;i++,r--,h--){
sum+=r*r*h;
}
}
void dfs(int x,int curv,int curs,int lastr,int lasth){
if(curs+costs[m-x+1]>ans) return;
//2.if(x>1 && curv+maxv(lastr-1,lasth-1,m-x+1)<1)return;
if(x==m+1){
if(curv==v){
ans=min(ans,curs);
}
return;
}
if(curv+costv[m-x+1]>v)return;
for(int r=min(lastr-1,(int)sqrt(v-curv));r>=m-x+1;r--){
for(int h=m-x+1;h<=min(lasth-1,(v-curv)/r/r);h++){ //3.for(int h=m-x+1;h<=min(lasth,(v-curv)/r/r);h++){
//4.
if (curs + (double)2 * (v - curv) / r > ans) continue;
if(x!=1) dfs(x+1,curv+r*r*h,curs+2*r*h,r,h);
else dfs(x+1,curv+r*r*h,curs+2*r*h+r*r,r,h);
}
}
}
void premake(){
for(int i=1;i<=m;i++){
costv[i]=costv[i-1]+(i*i*i);
costs[i]=costs[i-1]+2*i*i;
}
}
int main(){
cin>>v>>m;
ans=INF;
premake();
dfs(1,0,0,INF,INF);
cout<<(ans==INF?0:ans);
return 0;
}
```
by dtw35l @ 2024-08-01 17:25:07
鬼知道我找了多久
by dtw35l @ 2024-08-01 17:25:48