Problem Description
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.
 
Input
Process till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).
 
Output
Print each answer in a single line.
 
Sample Input
13
100
200
1000
 
Sample Output
1
1
2
2
 
Author
wqb0039
 
Source
 

题解:

设f[i][j][r][0/1]表示i位数(可含前导0)第一位为j,mod13的余数是r,有没有出现13(0/1)的数有几个

code:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxl=;
const int maxnum=;
const int rest=;
int n,power[maxl],f[maxl][maxnum][rest][],a[maxl];
void init(){
power[]=;
for (int i=;i<=;i++) power[i]=power[i-]*%;
f[][][][]=;
for (int i=;i<=;i++) for (int j=;j<=;j++)
for (int k=;k<=;k++) for (int r=;r<;r++){
int tmp=(r+j*power[i])%;
if (!(j==&&k==)) f[i][j][tmp][]+=f[i-][k][r][];
else f[i][j][tmp][]+=f[i-][k][r][];
f[i][j][tmp][]+=f[i-][k][r][];
}
}
int calc(int n){
int ans=,t=n,len=,r=,tmp;
bool flag=;
memset(a,,sizeof(a));
while (t) a[++len]=t%,t/=;
for (int i=len;i;i--){
for (int j=;j<a[i];j++){
tmp=((-(r+j*power[i]))%+)%;
for (int k=;k<=;k++) ans+=f[i-][k][tmp][];
if (!flag){
if (a[i+]==){if (j==) for (int k=;k<=;k++) ans+=f[i-][k][tmp][];}
if (j==) ans+=f[i-][][tmp][];
}
else for (int k=;k<=;k++) ans+=f[i-][k][tmp][];
}
r+=a[i]*power[i],r%=;
if (a[i+]==&&a[i]==) flag=;
}
return ans;
}
int main(){
init();
while (~scanf("%d",&n)) printf("%d\n",calc(n+));
return ;
}

hdu3652B-number的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. 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.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  10. [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 ...

随机推荐

  1. 安装rabbitmq集群

    一.安装 erlang.rabbitmq 在10.0.0.45.10.0.0.57.10.0.0.58三个节点上安装,然后开启 RabbitMQ 监控插件 以下在root用户操作 1./etc/hos ...

  2. Mina学习之与Spring整合

    本章中演示在Spring中整合Mina,为了整合到Spring,需要做以下几个步骤: 1. 设置IoHandler <bean id="trapHandler" class= ...

  3. 【设计模式 - 18】之备忘录模式(Memento)

    1      模式简介 备忘录模式的定义: 备忘录模式保存一个对象的某个状态,以便在适当的时候恢复对象,用作"后悔药",即取消上次操作或返回到以前的某个版本. 备忘录模式的应用实例 ...

  4. memcached的基本命令(安装、卸载、启动、配置相关)

    memcached的基本命令(安装.卸载.启动.配置相关):-p 监听的端口 -l 连接的IP地址, 默认是本机  -d start 启动memcached服务 -d restart 重起memcac ...

  5. max_connections 与 max_used_connections --ERROR 1040: Too many connections

    mysql> show variables like 'max_connections'; +-----------------+-------+ | Variable_name | Value ...

  6. java文件处理工具类

    import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...

  7. Linux shell用法和技巧

         使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和l技巧.当然,命令我能记住,但我不敢说能记得如何用它执行某个特定任务.于是,我开始在一个文本文件里记录这 ...

  8. iOS图片压缩

    项目中常会遇到,上传图片的操作,由于iPhone手机直接拍照的图片往往比较大,一般3-4M,如果直接上传不做处理会浪费用户很多流量,再者有很多场景并不需要高清图片,所以在上传图片前对图片进行压缩,是很 ...

  9. web前端:js

    内嵌样式<script></script> alert(“123”)弹出对话框 document.write(“test”) 引入方式 <title></ti ...

  10. ASP+MYSQL的配置及乱码解决

    TempStr = "driver={MySQL ODBC 3.51 Driver};database="&strDB&";server="&a ...