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

你可能感兴趣的文章
nginx+tomcat单个域名及多个域名配置
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Vue中向js中传递参数并在js中定义对象并转换参数
查看>>
Nginx、HAProxy、LVS
查看>>
nginx一些重要配置说明
查看>>
Nginx一网打尽:动静分离、压缩、缓存、黑白名单、跨域、高可用、性能优化......
查看>>