一道思维题?!
找到最⼤大的a使得a^3不超过m,接下来X的第⼀一块积⽊木必然为a或a-1
1.⽤用a,m2=m-a^3
2.⽤用a-1, X最⼤大为a^3-1, m2 = a^3-1-(a-1)^3=a^2-a
3.⽤用a-2, X最⼤大为(a-1)^3-1,m2=(a-1)^3-1-(a-2)^3=a^2-3a+6
显然2⼀一定比3优
每次m都会变成前⼀一个m^(2/3)
#include<cstdio> #include<cstring> #include<cmath> #define ll long long using namespace std; ll m,num,siz; void dfs(ll x,ll y,ll z) { if(!x) { if(y > num || (y == num && z > siz)) { num = y; siz = z; } return; } ll a= (ll)pow(x,1.0/3); ll i = 0; while(++i) { ll cnt = a + i; if(cnt * cnt * cnt > x) { i--; break; } } a = a + i; dfs(x-a*a*a,y+1,z+a*a*a); dfs(a*a*a-1-(a-1)*(a-1)*(a-1),y+1,z+(a-1)*(a-1)*(a-1)); } int main() { scanf("%lld",&m); dfs(m,(ll)0,(ll)0); printf("%lld %lld ",num,siz); return 0; }