题解 | #可爱の星空#

可爱の星空

https://ac.nowcoder.com/acm/problem/20650

#include <iostream>

using namespace std;

long long dfs(long long x)
{
    if(x == 1 || x == 2) return 0;
    else
    {
        if(x % 2) return dfs(x / 2 + 1) + dfs(x / 2) + 1;
        else return dfs(x / 2) + dfs(x / 2);
    }
}

int main()
{
    int t;
    cin >> t;
    
    while(t --)
    {
        long long n;
        cin >> n;
        
        cout << dfs(n) << endl;
    }
    
    return 0;
}
如何证明dfs出的一定是最优?
全部评论

相关推荐

CARLJOSEPH...:宝宝你戾气太大了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务