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

你可能感兴趣的文章
Neo4j(1):图数据库Neo4j介绍
查看>>
Neo4j(2):环境搭建
查看>>
Neo4j(3):Neo4j Desktop安装
查看>>
Neo4j(4):Neo4j - CQL使用
查看>>
Neo图数据库与python交互
查看>>
NEO改进协议提案1(NEP-1)
查看>>
Neo私链
查看>>
NervanaGPU 项目使用教程
查看>>
Nerves 项目教程
查看>>
nessus快速安装使用指南(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Nessus漏洞扫描教程之配置Nessus
查看>>
Nest.js 6.0.0 正式版发布,基于 TypeScript 的 Node.js 框架
查看>>
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
查看>>
nestesd exception is java .lang.NoSuchMethodError:com.goolge.common.collect
查看>>
nestJS学习
查看>>
net core 环境部署的坑
查看>>
NET Framework安装失败的麻烦
查看>>
Net 应用程序如何在32位操作系统下申请超过2G的内存
查看>>
Net.Framework概述
查看>>
NET3.0+中使软件发出声音[整理篇]<转>
查看>>