[BZOJ5064]B-number
[BZOJ5064]B-number
题目大意:
求\(1\sim n(n\le10^{15})\)间有多少数满足是\(13\)的倍数且包含字符串\(13\)。
思路:
数位DP。\(f[i][j][k]\)表示考虑\(i\)位,模\(13\)余数是\(j\),上一位数字是\(k\)时的方案数。
源代码:
#include<cstdio>
#include<cctype>
#include<utility>
#include<cstring>
typedef long long int64;
inline int64 getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int64 x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
int d[16];
int64 pwr[16];
typedef std::pair<int64,int64> Node;
Node f[16][13][10];
Node dp(const int &dep,const bool &zero,const bool &limit,const int &r,const int &last) {
if(dep==0) return std::make_pair(!zero&&!r,0);
const int lim=limit?d[dep]:9;
if(!zero&&!limit&&f[dep][r][last]!=(Node){-1,-1}) return f[dep][r][last];
Node ret=std::make_pair(0,0);
for(register int i=0;i<=lim;i++) {
const Node p=dp(dep-1,zero&&!i,limit&&i==lim,(r+i*pwr[dep])%13,i);
if(last==1&&i==3) {
ret.second+=p.first;
} else {
ret.first+=p.first;
}
ret.second+=p.second;
}
if(!zero&&!limit) f[dep][r][last]=ret;
return ret;
}
inline int64 solve(int64 x) {
for(;x;x/=10) {
d[++d[0]]=x%10;
pwr[d[0]]=d[0]==1?1:pwr[d[0]-1]*10%13;
}
return dp(d[0],true,true,0,0).second;
}
int main() {
memset(f,-1,sizeof f);
const int64 n=getint();
printf("%lld\n",solve(n));
return 0;
}
[BZOJ5064]B-number的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
随机推荐
- Gson解决字段为空是报错的问题
json解析有很多工具,这里说的是最常用也是解析速度最快的Gson,Gson是google家出的,有一个缺点就是无法设置null替换, 我们只能手动的批量替换服务器返回的null了,正常的接口定义的时 ...
- NPOI操作Excel(一)--NPOI基础
用C#读取Excel的方法有很多中,由于近期工作需要,需要解析的Excel含有合并单元格以及背景色等特殊要求,故在网上查了一些关于读Excel的方法的优缺点,觉得NPOI能满足我的需要,所以搜索了一些 ...
- 安装Mysql5.6.19
存在异常: ERROR (HY000): Can't connect to MySQL server on 'localhost' (10061) 原因:Mysql的服务没有启动 windows7启动 ...
- Django系列(一)
项目引入静态文件 更改settings.py,为项目下面的每个APP应用,建立静态文件,这里如blog,首先在blog下面建立一个静态文件夹名为statics,注意这里为别名 STATICFILES_ ...
- 想要将我们的OSGi框架中的批量日志单独打印到文件中
我们的日志虽然没有直接依赖logback,但遗憾的是也没有使用slf4j,而是使用了Apache Common-Logging slf4j 和 common-logging有什么区别呢 common- ...
- javaScript事件(八)事件类型之变动事件
DOM2级的变动(mutation)事件能在DOM中某一部分发送变化时给出提示.变动事件为XML或HTML DOM设计的,并不特定于某种语言.DOM2级定义了如下变动事件. DOMSubtreeMod ...
- Java数据结构与算法结构图
- Filebeat6.31整合Kafka集群消息队列(三)
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.3.2-linux-x86_64.tar.gz [root@ ...
- net core体系-API-1Ocelot-(3)简单项目实战
首先,让我们简单了解下什么是API网关? API网关是一个服务器,是系统的唯一入口.从面向对象设计的角度看,它与外观模式类似.API网关封装了系统内部架构,为每个客户端提供一个定制的API.它可能还具 ...
- Python学习(二十九)—— pymysql操作数据库优化
转载自:http://www.cnblogs.com/liwenzhou/articles/8283687.html 我们之前使用pymysql操作数据库的操作都是写死在视图函数中的,并且很多都是重复 ...