这玩意好像甚至有递推式……不太懂

(为什么是图片?cnblogs 第一个公式没渲染成功)

时间复杂度是 \(O(4^{\deg F}\log K)\) 的。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=100;
int f[17][maxn],cur[10],al[4];
int calc(int K){
// cerr<<"___________________________________"<<endl;
// cerr<<"solve "<<K<<endl;
memset(f,0,sizeof(f));
f[1][1]=1;
for(int R=2;R<=62;R++){
if(K&(1ll<<R-2)){
for(int j=0;j<4;j++)al[j]=0;
for(int j=0;j<16;j++)al[0]+=(j&1)*(1<<j);
for(int j=0;j<16;j++)al[1]+=(__builtin_popcount(j)&1)*(1<<j);
for(int j=0;j<16;j++)al[2]+=(((j&1)+((j>>1)&1)+((j>>2)&1))&1)*(1<<j);
for(int j=0;j<16;j++)al[3]+=((((j>>1)&1)+((j>>3)&1))&1)*(1<<j);
for(int j=1;j<16;j++){
int c1=(1<<16)-1,c2=0;
for(int k=0;k<4;k++){
if(j&(1<<k))c1=c1&al[k];
else c2=c2|al[k];
}
int x=c1-(c1&c2);
for(int l=0;l<16;l++)if((1<<l)&x)f[j][R]+=f[l][R-1];
}
for(int j=0;j<4;j++)al[j]=0;
for(int j=0;j<16;j++)al[0]+=(((j&1)+((j>>2)&1))&1)*(1<<j);
for(int j=0;j<16;j++)al[1]+=((((j>>1)&1)+((j>>2)&1)+((j>>3)&1))&1)*(1<<j);
for(int j=0;j<16;j++)al[2]+=(__builtin_popcount(j)&1)*(1<<j);
for(int j=0;j<16;j++)al[3]+=((j>>3)&1)*(1<<j);
for(int j=1;j<16;j++){
int c1=(1<<16)-1,c2=0;
for(int k=0;k<4;k++){
if(j&(1<<k))c1=c1&al[k];
else c2=c2|al[k];
}
int x=c1-(c1&c2);
for(int l=0;l<16;l++)if((1<<l)&x)f[j][R]+=f[l][R-1];
}
}else{
for(int j=0;j<4;j++)al[j]=0;
for(int j=0;j<16;j++)al[0]+=(j&1)*(1<<j);
for(int j=0;j<16;j++)al[2]+=((j>>1)&1)*(1<<j);
for(int j=1;j<16;j++){
int c1=(1<<16)-1,c2=0;
for(int k=0;k<4;k++){
if(j&(1<<k))c1=c1&al[k];
else c2=c2|al[k];
}
int x=c1-(c1&c2);
for(int l=0;l<16;l++)if((1<<l)&x)f[j][R]+=f[l][R-1];
}
for(int j=0;j<4;j++)al[j]=0;
for(int j=0;j<16;j++)al[0]+=((j>>2)&1)*(1<<j);
for(int j=0;j<16;j++)al[2]+=((j>>3)&1)*(1<<j);
for(int j=1;j<16;j++){
int c1=(1<<16)-1,c2=0;
for(int k=0;k<4;k++){
if(j&(1<<k))c1=c1&al[k];
else c2=c2|al[k];
}
int x=c1-(c1&c2);
for(int l=0;l<16;l++)if((1<<l)&x)f[j][R]+=f[l][R-1];
}
}
// for(int j=0;j<16;j++)cerr<<f[j][R]<<" ";cerr<<endl;
}
int ans=0;
for(int i=0;i<16;i++)ans+=f[i][62]*__builtin_popcount(i);
// cerr<<K<<" ans = "<<ans<<endl;
return ans;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// cout<<calc(100)<<endl;
int K,res=0;cin>>K;
for(int i=1,z=1;i<=K;i++)z=z*10,res+=calc(z);
cout<<res<<endl;
return 0;
}

Project Euler 588 题解的更多相关文章

  1. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  2. Python练习题 040:Project Euler 012:有超过500个因子的三角形数

    本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...

  3. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  4. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  5. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  6. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  7. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  8. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  9. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  10. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. Java方法参数太多怎么办—Part 1—自定义类型

    本文由 ImportNew - 王村平 翻译自 dzone.如需转载本文,请先参见文章末尾处的转载要求. 本文是这个系列的第一篇文章,介绍了采用自定义类型处理参数过多的问题.如果你也希望参与类似的系列 ...

  2. Django之项目部署

    1.线上部署一般会使用https的方式进行部署,本身django框架是不支持的,所以需要... 1)安装扩展 pip install django-extensions django-werkzeug ...

  3. .NET 中的中间件(Middleware)

    ASP.NET Core 中间件 什么是中间件(Middleware)? 中间件是组装到应用程序管道中以处理请求和响应的软件. 每个组件: 选择是否将请求传递给管道中的下一个组件. 可以在调用管道中的 ...

  4. 【Amadeus原创】SQL Server查询某数据库所有表名行数和空间占用率

    ` select object_name(id) tablename, 8reserved/1024 reserved, rtrim(8dpages)+'kb' used, 8(reserved-dp ...

  5. 源启行业AI平台 银行智能业务的驱动引擎

    AI技术已经深入金融行业,在营销.渠道.风控等领域广泛应用,但人工智能开发与应用面临成本高.难度大.门槛高.重复建设.无统一管理复用AI模型资产等问题,这些问题也正是源启AI行业平台要解决的. 源启行 ...

  6. 在.NET Core中使用异步多线程高效率的处理大量数据的最佳实践

    目录 一.引言 二.假设场景 三.解决方案 四.示例代码 一.引言 处理大量数据是一个常见的需求,传统的同步处理方式往往效率低下,尤其是在数据量非常大的情况下.本篇将介绍一种高效的多线程异步处理大数据 ...

  7. 2024年1月Java项目开发指南3:创建Springboot项目

    本文档编写于贰零贰肆年一月八日@萌狼蓝天 如果你不知道什么是springboot,那么你只需要知道,这是一个让我们减少配置工作量,方便开发的开发框架,能让我们更专心于业务开发,省的被各种各样的配置浪费 ...

  8. 【Python】【Jupyter】Jupyter 的简单使用 与 Python的基本输出输入

    上课无聊写着玩的,不必当真. Jupyter 的简单使用 与 Python的基本输出输入 目录 Jupyter 的简单使用 与 Python的基本输出输入 数据准备 输出 输入 一些练习 print( ...

  9. linux系统命令make.clean的用法讲解

    先先看一下什么是makefile makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Sh ...

  10. SolidState靶机通关教程及提权

    声明!本文章及工具分享仅仅只是供大家学习交流为主,如有任何触犯法律的行为,均与本人及团队无关!!! 工具链接:https://pan.quark.cn/s/33795a10039c 一.靶机搭建 点击 ...