博客
关于我
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/

你可能感兴趣的文章
Needle in a haystack: efficient storage of billions of photos 【转】
查看>>
NeHe OpenGL教程 07 纹理过滤、应用光照
查看>>
NeHe OpenGL教程 第四十四课:3D光晕
查看>>
Neighbor2Neighbor 开源项目教程
查看>>
neo4j图形数据库Java应用
查看>>
Neo4j图数据库_web页面关闭登录实现免登陆访问_常用的cypher语句_删除_查询_创建关系图谱---Neo4j图数据库工作笔记0013
查看>>
Neo4j图数据库的介绍_图数据库结构_节点_关系_属性_数据---Neo4j图数据库工作笔记0001
查看>>
Neo4j图数据库的数据模型_包括节点_属性_数据_关系---Neo4j图数据库工作笔记0002
查看>>
Neo4j安装部署及使用
查看>>
Neo4j电影关系图Cypher
查看>>
Neo4j的安装与使用
查看>>
Neo4j(1):图数据库Neo4j介绍
查看>>
Neo4j(2):环境搭建
查看>>
Neo4j(3):Neo4j Desktop安装
查看>>
Neo4j(4):Neo4j - CQL使用
查看>>
Neo图数据库与python交互
查看>>
NEO改进协议提案1(NEP-1)
查看>>
Neo私链
查看>>
NervanaGPU 项目使用教程
查看>>
Nerves 项目教程
查看>>