给你m,让你选一个不超过m的数字X,然后每次都选最大的a3≤X
然后X=X−a3,然后继续这么操作
先最大化操作次数,然后最大化X
一般这种都是二分,但是这题不是,是一个贪心
考虑第一块取多少,最大的a3≤m
如果取a,还剩m−a3
取a−1的话,那肯定最大的X是a3−1,剩下a3−1−(a−1)3
如果取a−2的话,肯定没有a−1来的优,因为剩下的比取a−1剩下的要少
所以就是取a或者a−1,然后对于每次剩下的都可以这么考虑
如果你问,剩下x的时候,不是应该要取最大的a么
所以我们开头假设的X,不一定是最终的X
最后根据你取的,重新安排开头的X
比如这会剩x,然后取a−1,x当作了a3−1−(a−1)3
那么只要在最开始的时候X取小一点就行了
所以dfs的时候记录个数,还剩多少,∑a3
代码:
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define MAX 10000005
#define MAXN 1000005
#define maxnode 205
#define sigma_size 2
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define middle int m=(r+l)>>1
#define LL long long
#define ull unsigned long long
#define mem(x,v) memset(x,v,sizeof(x))
#define lowbit(x) (x&-x)
#define pii pair<int,LL>
#define bits(a) __builtin_popcount(a)
#define mk make_pair
#define limit 10000
//const int prime = 999983;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f;
//const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const LL mod = 1e8+9;
const ull mx = 133333331;
/*****************************************************/
inline void RI(int &x) {
char c;
while((c=getchar())<'0' || c>'9');
x=c-'0';
while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
/*****************************************************/
pii dfs(int num,LL re,LL all){
if(re==0) return mk(num,all);
LL a=1;
while(a*a*a<=re) a++;
a--;
pii ans=dfs(num+1,re-a*a*a,all+a*a*a);
if(a-1) ans=max(ans,dfs(num+1,a*a*a-1-(a-1)*(a-1)*(a-1),all+(a-1)*(a-1)*(a-1)));
return ans;
}
int main(){
LL m;
while(cin>>m){
LL a=1;
while(a*a*a<=m) a++;
a--;
pii ans=dfs(1,m-a*a*a,a*a*a);
if(a-1) ans=max(ans,dfs(1,a*a*a-1-(a-1)*(a-1)*(a-1),(a-1)*(a-1)*(a-1)));
cout<<ans.first<<" "<<ans.second<<endl;
}
return 0;
}