[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 ... 
随机推荐
- C++ Primer 笔记——重载运算
			1.对于二元运算符来说,左侧运算对象传递给第一个参数,而右侧运算对象传递给第二个参数.除了重载的函数调用运算符operator()之外,其他重载元素运算符不能含有默认实参. class test { ... 
- MySQL修改数据表存储引擎的3种方法介绍
			这篇文章主要介绍了MySQL修改数据表存储引擎的3种方法介绍,分别是直接修改.导出导入.创建插入3种方法, 可以参考下 MySQL作为最常用的数据库,经常遇到各种各样的问题.今天要说的就是表存储引 ... 
- Java接口自动化测试之HTTPClient学习(四)
			pom.xml 文件中dependency <dependencies> <dependency> <groupId>org.testng</groupId ... 
- php归档格式:phar文件详解(创建、使用、解包还原提取)
			转载一篇,突然遇到一个冷知识,phar的东东,貌似和jar.war是一种鬼. 重点使用一下下面这个东东,就能解包出来东东了. $phar = new Phar('lib/yunke.phar', 0) ... 
- ElasticSearch简要总览
			今天看了一下ElasticSearch的相关文档,我做了如下总结: 发现越来越喜欢画图归纳总结知识了,看图说话 集群特性说明 健康状况的说明 如何配置分片? 接下来一张图总结下操作相关的总结 接下来, ... 
- SSO单点登录原理
			一.单系统登录机制 1.http无状态协议 web应用采用browser/server架构,http作为通信协议.http是无状态协议,浏览器的每一次请求,服务器会独立处理,不与之前或之后的请求产生关 ... 
- Mafly.Mail实现发送邮件
			安装 打开程序包管理器控制台,执行命令:Install-Package Mafly.MailInstall-Package Newtonsoft.Json.dll 安装之后,项目会自动创建一个Conf ... 
- Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试
			标签:Linux 域名 Nginx 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://xpleaf.blog.51cto.com/9 ... 
- Fatal NI connect error 6413的解决办法 http://www.itpub.net/thread-107518-1-1.html
			在进行Oracle开发的时候,碰到了这样一个稀奇古怪的问题:每次连接数据库都不成功,并且在应用程序目录下的sqlnet.log中有这样的记录: Fatal NI connect error 6413, ... 
- net core体系-web应用程序-4asp.net core2.0 项目实战(1)-5项目数据库操作封装操作-EF框架
			EF框架有三种基本的方式:DB First(数据库优先),Model First(模型优先),Code First(代码优先). Entity Framework4.1之前EF支持“Database ... 
