传送门:
https://abc050.contest.atcoder.jp/tasks/arc066_b
怎么说呢
这题一上来就只会头铁地硬算...
首先打表,可以发现前几项有:1、2、4、5、8、10、13、14、18、21、26、28、33、36、40、41、46、50、57、60、68
可以发现:
因此直接用数组记录前面已有的项目,再开一个 map 用于记忆化搜索,然后递归即可。
这就是莽夫解法了...
我还没看懂...等我想明白了再补上题解...
#include <map>
#include <iostream>
using namespace std;
#define ll long long
const int mod=1e9+7;
map<ll,ll> f;
ll Dp(ll x){
if(f[x]) return f[x];
return (f[x]=(Dp(x/2)+Dp((x-1)/2)+Dp((x-2)/2))%mod);
}
int main(){
ll n;
cin>>n;
f[0]=1;
f[1]=2;
cout<<Dp(n)<<endl;
return 0;
}