[ABC340C] Divide and Divide tj
_colin1112_ · · 题解
思路
容易得出 map 记忆化即可。
Code
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
const int E = 1e6 + 5;
ll n;
unordered_map<ll, ll> mp;
inline ll dfs(ll x)
{
if (mp[x] != 0)
return mp[x];
if (x <= 1)
return 0;
ll ans = x;
ans += dfs(x / 2) + dfs(x - x / 2);
mp[x] = ans;
return ans;
}
int main()
{
// mp[2] = 2;
cin >> n;
cout << dfs(n);
return 0;
}