|
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- using namespace std;
- #define FOR(i,a,b) for(register int i(a);i<=b;++i)
- #define For(i,a,b) for(register int i(a);i>=b;--i)
- int mins[20],minv[20];
- int ans=1<<30,s;
- bool prune(int maxh,int maxr,int n,int v)
- {
- int cc=0;
- FOR(i,0,n-1) cc+=(maxh-i)*(maxr-i)*(maxr-i);
- if(cc<v) return 1;
- else return 0;
- }
- void dfs(int maxh,int maxr,int n,int v,int m)
- {
- if(n==0)
- {
- if(v) return;
- ans=min(ans,s);
- }
- if(s+mins[n]>ans) return;
- if(maxh<n||maxr<n) return;
- if(minv[n]>v) return;
- if(prune(maxh,maxr,n,v)) return;
- For(i,maxr,n)
- {
- if(n==m) s=i*i;
- For(j,maxh,n)
- {
- s+=2*i*j;
- dfs(j-1,i-1,n-1,v-i*i*j,m);
- s-=2*i*j;
- }
- }
- }
- int main()
- {
- int n,m;scanf("%d%d",&n,&m);
- FOR(i,1,m)
- mins[i]=mins[i-1]+2*i*i,
- minv[i]=minv[i-1]+i*i*i;
- if(n<minv[m]) printf("0");
- else
- {
- int maxh=(n-minv[m-1])/(m*m)+1;
- int maxr=sqrt((n-minv[m-1])/m)+1;
- dfs(maxh,maxr,m,n,m);
- if(ans==1<<30) printf("0");
- else printf("%d",ans);
- }
- return 0;
- }
复制代码 |
|