博客
关于我
AT2272 [ARC066B] Xor Sum 题解
阅读量:452 次
发布时间:2019-03-06

本文共 1060 字,大约阅读时间需要 3 分钟。

题目连接:

分析

这道题只看题目中给的样例是找不出规律的

所以我们可以打一下表

1, 2, 4, 5, 8, 10, 13, 14, 18

如果你还是没有看出什么规律的话,我们可以从OEIS上搜索一下

网址:

把这一个数列输入到搜索框,然后就会出现下面的页面

第一个就是我们想要的数列

大家可以看一下上面的证明和递推式(都是英文

所以我们可以得到\(f[x]=f[x/2]+f[(x-1)/2]+f[(x-2)/2]\)

证明摘自洛谷:

代码

#include
#include
#define ll long longusing namespace std;const int Mod=1e9+7;map
dp;ll dfs(ll x){ if(dp[x])return dp[x]; return dp[x]=(dfs(x>>1)+dfs(x-1>>1)+dfs(x-2>>1))%Mod;}int main(){ ll n; scanf("%lld",&n); dp[0]=1; dp[1]=2; ll res=dfs(n)%Mod; printf("%lld\n",res);}
//打表#include
#include
#include
using namespace std;typedef long long ll;const ll mod=1e9+7;map
ma;ll a[50]={1,2,4,5,8,10,13,14,18,21,26,28,33,36,40,41,46,50,57,60,68};ll solve(ll xx){ if(xx<=20) return a[xx]; if(ma[xx]) return ma[xx]; if(xx%2) return ma[xx]=(2*solve(xx/2)%mod+solve(xx/2-1)%mod)%mod; else return ma[xx]=(2*solve(xx/2-1)%mod+solve(xx/2)%mod)%mod;}int main(){ ll n; scanf("%lld",&n); ll ans=solve(n); printf("%lld\n",ans); return 0;}

转载地址:http://plpyz.baihongyu.com/

你可能感兴趣的文章
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>