[HDU_3652]B-number
题目描述
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.
输入
输出
样例输入
13
100
200
1000
样例输出
1
1
2
2 求小于n是13的倍数且含有“13”的数的个数,有多组数据,输入到结束。 dp[i][j][k][l]。i表示i位数j表示第i位是j的k表示是否包含13(k==0 or 1)L表示膜13是l的数的个数
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[][][][];
int e[];
void init()
{
e[]=;
for(int i=;i<=;i++)e[i]=(e[i-]*)%;
dp[][][][]=;
for(int i=;i<=;i++)
for(int j1=;j1<=;j1++)
for(int j2=;j2<=;j2++)
for(int l=;l<;l++)
{
int yu=(l-(j1*e[i-])%+)%;//yu表示dp[][][][l]从dp[][][][yu]转移//yu+j1贡献的余数=l
dp[i][j1][][l]+=dp[i-][j2][][yu];
if(j1==&&j2==)dp[i][j1][][l]+=dp[i-][j2][][yu];
else dp[i][j1][][l]+=dp[i-][j2][][yu];
}
}
int solve(int a)
{
int len=,ans=,mod=,d[];bool t=;
while(a)
{
d[++len]=a%;a/=;
}
d[len+]=;
for(;len>=;len--)
{
for(int i=;i<d[len];i++)
{
int yu=(-(mod*e[len])%)%;//算上高位mod13的余数还要加多少(yu)mod13才会得0
ans+=dp[len][i][][yu];
if(t||d[len+]==&&i==)ans+=dp[len][i][][yu];
}
if(d[len+]==&&d[len]==)t=;
mod=(mod*+d[len])%;
}
return ans;
}
int main()
{
int n;init();
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",solve(n+));
}
return ;
}
[HDU_3652]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 ...
随机推荐
- MAC下MySQL初始密码忘记修改初始密码
解决MAC下MySQL忘记初始密码的方法分享给大家,供大家参考,具体内容如下 第一步: 点击系统偏好设置->最下边点MySQL,在弹出页面中,点击stop MySQL Servier,输入密码关 ...
- [Luogu1341]无序字母对(欧拉回路)
按题意给定字符串建无向图,找欧拉回路 按照定义,当没有奇数度点或者只有2个奇数度点时才有欧拉回路 Code #include <cstdio> #include <algorithm ...
- rpm、yum命令
一.rpm命令 挂载光盘文件到/media目录: 进去/media目录下的Packages目录: 查看系统已安装的所有rpm包: 查看系统是否安装dhcp软件包: 安装dhcp软件包: 查看dhcp软 ...
- MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':ge
数据库表里命名有这个字段,可怎么就是报错呢,大神的解释: 加上之后立马好用!!!
- spring源码学习中的知识点
一.循环依赖 循环依赖就是循环引用,就是两个或多个bean之间互相持有对方. 1.构造器循环依赖 表示通过构造器注入造成的循环依赖,此依赖是无法解决的,只能抛出BeanCurrentlyInCreat ...
- 20145202马超 《Java程序设计》第六周学习总结
进程:是一个正在执行中的程序,每一个进程都有一个执行程序,该顺序是一个执行路径,或者说是一个控制单元. 线程:就是进程中的一个独立的控制单元,线程在控制着进程的执行. 一个进程至少有一线程. Java ...
- 1079: [SCOI2008]着色方案
链接 思路 首先是dp,如果直接用每个种颜色的剩余个数做状态的话,复杂度为5^15. 由于c<=5,所以用剩余数量的颜色的种类数做状态:f[a][b][c][d][e][last]表示剩余数量为 ...
- laravel5.5配置信息
目录 1 环境配置 1.1 检索环境配置 1.2 确定当前环境 2 访问配置值 3 配置缓存 4 维护模式 配置文件在config目录下,为了便于不同人员的开发,我们可以使用不同的.env文件来配置各 ...
- 剑指Offer - 九度1518 - 反转链表
剑指Offer - 九度1518 - 反转链表2013-11-30 03:09 题目描述: 输入一个链表,反转链表后,输出链表的所有元素.(hint : 请务必使用链表) 输入: 输入可能包含多个测试 ...
- HUAWEI TAG-AL00 找IMEI的过程
前几天,遇到一台华为机型,IMEI获取有问题,然后就找了一下. 以下是解决过程,权当记录一下,尽管为知笔记已经有备份了 :) 0x01: 起因 测试小哥发现,一台机型IMEI获取不全,有问题,拨号页面 ...