Codeforces 680D - Bear and Tower of Cubes

680D - Bear and Tower of Cubes

思路:dfs+贪心,设剩余的体积为res,存在a,使得a≤ res,每次取边长为a的立方体或者边长为a-1的立方体(这时体积上限变成a-1)。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset((a),(b),sizeof(a))
#define pil pair<int,ll>
#define mp make_pair
const int N=1e5+5;
ll mm[N];

pil dfs(int cur,ll res,ll x)
{
    //cout<<res<<endl;
    if(res==0)
    {
        //cout<<cur<<' '<<x<<endl;
        return mp(cur,x);
    }
    int a=upper_bound(mm+1,mm+N,res)-mm;
    a--;
    pil ans=dfs(cur+1,res-mm[a],x+mm[a]);
    if(a>1)ans=max(ans,dfs(cur+1,mm[a]-1-mm[a-1],x+mm[a-1]));
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll m;
    cin>>m;
    for(int i=1;i<N;i++)mm[i]=(ll)i*i*i;
    
    int a=upper_bound(mm+1,mm+N,m)-mm;
    a--;
    pil ans=dfs(1,m-mm[a],mm[a]);
    if(a>1)ans=max(ans,dfs(1,mm[a]-1-mm[a-1],mm[a-1]));
    cout<<ans.first<<' '<<ans.second<<endl;
    return 0;
}

 

转载于:https://www.cnblogs.com/widsom/p/7371581.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值