[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 ...
随机推荐
- selenium 操作复选框
场景 从上一节的例子中可以看出,webdriver可以很方便的使用findElement方法来定位某个特定的对象,不过有时候我们却需要定位一组对象, 这时候就需要使用findElements方法. 定 ...
- chart API笔记
1. 参数说明 http://chart.apis.google.com/chart? chs=250x100 &chd=t:60,40 &cht=p3 &chl=Hello| ...
- 【转】asp.net Core 系列【二】—— 使用 ASP.NET Core 和 VS2017 for Windows 创建 Web API
在本教程中,将生成用于管理“待办事项”列表的 Web API. 不会生成 UI. 概述 以下是将创建的 API: API 描述 请求正文 响应正文 GET /api/todo 获取所有待办事项 无 待 ...
- idea的操作
- mysql如何在一张表中插入一万条数据?(用存储过程解决)
写一个存储过程,里面写一个循环,就可以了.主键你现在不是自增的,所以写语句的时候,就Insert到3个字段中. DELIMITER $$ DROP PROCEDURE IF EXISTS `proc_ ...
- .Net页面缓存OutPutCache详解
一 它在Web.Config中的位置 <system.web> <!--页面缓存--> <caching> <outputCacheSettings> ...
- C#矩阵求逆
来源:http://zhidao.baidu.com/link?url=DiqAbq9YUYn3z7QjxGGoF0PLZwN-Y9ecqKB7Gy38JWRD1riMIYukVKXKq88pxtWL ...
- mysql 查询结果中增加序号
) as rownum,person_id from t_base_person
- spring的4种事务特性,5种隔离级别,7种传播行为
spring事务: 事务: 事务逻辑上的一组操作,组成这组操作的各个逻辑单元,要么一起成功,要么一起失败. 事务特性(4种): 原子性 (atomicity):强调事务的不可分割. 一致性 (con ...
- mysql binary
mysql在比较字符串的时候是忽略大些写的 比如有用户叫ABC和abc select * from `sys_user` where username = 'abc' 会出来两条记录 select * ...