codeforces679B Bear and Tower of Cubes【DFS】

题意:已知一座塔的最大体积为m . 现在求一个确切的x(1<=x<=m),使得x可以进行的操作次数最多,如果操作次数相同,输出最大的x。
每次操作:减去当前体积所能减去的最大立方数。(提升训练1-H)

不懂:不懂在dfs的原因

<table><tr><td bgcolor=#7FFFD4>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn=1e5+50;
ll a[maxn];
pair <ll,ll> ans;

void dfs(ll now,ll cnt,ll cur)
{
    if(!now)
    {
        ans=max(ans,make_pair(cnt,cur));
        return ;
    }
    int q=upper_bound(a+1,a+1+100000,now)-a;
    //cout << "wc" <<endl;
    q--;
    dfs(now-a[q],cnt+1,cur+a[q]);
    if(q>1) dfs(a[q]-1-a[q-1],cnt+1,cur+a[q-1]);
}

void init()
{
    for(int i=1;i<=maxn-50;i++)
        a[i]=1LL*i*i*i;
    return ;
}

int main(void)
{
    init();
    ll p;
    cin >> p;
    dfs(p,0,0);
    cout << ans.first << " " << ans.second << endl;
}

2017.08.15以后翻阅
http://blog.csdn.net/Somnus__poppy/article/details/51712385
http://www.cnblogs.com/d-e-v-i-l/p/5608079.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值