[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 ...
随机推荐
- stdio中牛逼的写法
用空间换时间的典型 /* * NOTE! This ctype does not handle EOF like the standard C * library is required to. */ ...
- Android 内嵌 HTML5 并进行交互
Android与HTML5的交互主要是两个部分, 与HTML5的交互以及与JavaScript的交互, 与HTML5的交互可以通过注册onclick事件转化为与JavaScript的交互 Androi ...
- MyBatis---集合查询(一对多)
这里的集合查询即一对多的数据联合查询.如一个用户多次登录的信息查询 要实现这样的联合查询需要在用户实体类中添加登录实体类的一个集合属性字段,表中不存在该字段. <resultMap id=&qu ...
- thinkphp3.1.3验证码优化
现状 thinkphp3.1.3版本中的验证码字符分布不均匀,在自定义宽高时很明显. 调用代码: Image::buildImageVerify(6, 5, 'png', 150, 50); 生成的验 ...
- 七夕蠕虫“XX神器”逆向分析
转载请注明出处 ____________________________________________________________________________________________ ...
- U盘的容量变小了怎么办?
之前买了个U盘,后来给朋友装系统弄成U盘启动盘了,就发现U盘容量变少了几百兆,原来是因为做U盘启动盘的时候,U盘启动盘制作软件都是把写入U盘的PE文件隐藏了,防止用户不小心删除文件. 所以说这些空间应 ...
- CentOS搭建pptpd服务笔记
pptpd.rpm 包下载.http://poptop.sourceforge.net/yum/stable/packages/ 参考资料:http://www.oschina.net/questio ...
- ptmalloc,tcmalloc和jemalloc内存分配策略研究 ? I'm OWen..
转摘于http://www.360doc.com/content/13/0915/09/8363527_314549949.shtml 最近看了glibc的ptmaoolc,Goolge的tcmall ...
- 给vmstat加上时间戳
vmstat -n 5 | awk '{print strftime("[%Y-%m-%d %H:%M:%S]"),$0}' 或者 vmstat -n 5 | awk '{ pri ...
- 【志银】php5.6-Apache2.4-mysql5.6环境配置(win7_64位)
----------------------------------------------------- ★软件工具:(下载时注意下载相应版本,不同版本安装细节可能会有差异!!) 1>http ...