A - B-number

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 数位dp
 //2016.8.7
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string> using namespace std; int dp[][][][];
//dp[i][j][k][p]表示方法数,i表示已处理的长度,j表示mod13的余数,k表示前缀是否相同(0为相同,1为不同),p为1表示前一个数为1,为2表示已出现13,否则为0
int mi[]; int cal(int x, int n, int p)
{
return x*mi[n]%p;
} int judge(int x)//三态函数
{
if(x==)return ;
else if(x==)return ;
else return ;
} int solve(string s)
{
memset(dp, , sizeof(dp));
dp[][][][] = ;
int len = s.size();
for(int i = ; i < len; i++)
for(int j = ; j < ; j++)
for(int k = ; k < ; k++)
for(int p = ; p < ; p++)
{
if(dp[i][j][k][p]!=)
{
int l, r;
l = ; r = (k==?s[i]-'':);
for(int x = l; x <= r; x++)
{
if(p==)
dp[i+][(j+cal(x, len-i-, ))%][(k==&&x==r)?:][x==?:]+=dp[i][j][k][p];
else if(p==)
dp[i+][(j+cal(x, len-i-, ))%][(k==&&x==r)?:][judge(x)]+=dp[i][j][k][p];
else if(p==)
dp[i+][(j+cal(x, len-i-, ))%][(k==&&x==r)?:][]+=dp[i][j][k][p];
}
}
}
return dp[len][][][] + dp[len][][][];
} int main()
{
string n;
while(cin>>n)
{
mi[] = ;
for(int i = ; i < ; i++)
mi[i] = mi[i-]*%;
int ans;
ans = solve(n);
cout<<ans<<endl;
} return ;
}

HDU3652(数位dp)的更多相关文章

  1. hdu3652 数位dp记忆化搜索

    从未见过的船新版本数位dp,,省去了预处理过程,直接进行计算 #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  2. HDU3652 B-number —— 数位DP

    题目链接:https://vjudge.net/problem/HDU-3652 B-number Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  3. 【HDU3652】B-number 数位DP

    B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...

  4. 数位DP HDU3652

    B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. hdu3652(数位dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3652 题意:求1~n含有13且能被13整除的数的个数. 分析:数位dp,dp数组加一维来维护到pos位 ...

  6. hdu3652 B-number 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3652 题意就是求区间内能被13整除并且包含”13“的数字的个数 感觉是比较中等的数位DP题目 我用的记 ...

  7. 【Hdu3652】B-number(数位DP)

    Description 题目大意:求小于n是13的倍数且含有'13'的数的个数. (1 <= n <= 1000000000) Solution 数位DP,题目需要包含13,且被13整除, ...

  8. HDU3652 B-number(数位DP)题解

    思路: 这里的状态分为3种,无13和末尾的1,无13且末尾为1,有13,然后DFS 等我搞清楚数位DP就来更新Orz 代码: #include<iostream> #include< ...

  9. 【hdu3652】数位dp(浅尝ACM-A)

    向大佬学习 第一次写博客有点紧张,也算是小萌新的突破吧 这次主要是总结一下校内的ACM比赛的各种题,主要是新思路以及学到的新知识 先放一张 下面开始说正事 题面 A wqb-number, or B- ...

随机推荐

  1. CodeForces 617E XOR and Favorite Number

    莫队算法. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> ...

  2. Web 网站 故障常用分析命令

    系统连接状态篇: 1.查看TCP连接状态 netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn netstat -n | awk '/^tcp/ { ...

  3. (中等) HDU 4370 0 or 1,建模+Dijkstra。

    Description Given a n*n matrix C ij (1<=i,j<=n),We want to find a n*n matrix X ij (1<=i,j&l ...

  4. 史上最坑的证书报错解决方法:Code=3000 "未找到应用程序的“aps-environment”的权利字符串"

    在ios注册远程通知获取设备令牌token的时候 // 注册远程通知获取设备令牌 toKen [[ UIApplication sharedApplication ] registerForRemot ...

  5. 利用jackson转成json字符串(ssh中)

    public String getJsonString(Object o){ ObjectMapper om = new ObjectMapper(); StringWriter sw = new S ...

  6. LearningDocker--Chapter3--Building images

    This chapter is quite different from the earlier ones, and it is in this chapter to clearly describe ...

  7. 使用Tomcat搭建图片服务器,使图片能够用链接访问

    在后台和前端交互时,遇到了后台存储的图片,前端根据地址无法访问,使用Tomcat搭建图片服务器 1.找到tomcat下的server.xml文件 2.配置文件下加入service节点 <!--为 ...

  8. ubuntu12.04+fuerte 下跑通lsd-slam——数据集

    lsd-slam(下载链接:https://github.com/tum-vision/lsd_slam)提供了两种方法,一种是用数据集(下载地址http://vision.in.tum.de/lsd ...

  9. 【java基础】内部类,局部内部类,匿名内部类、静态内部类、接口中的内部类

    内部类: 1.定义在一个类中的内部类,内部类的实例化伴随着外围类所定义的方法来构造,内部类对象有外围类的隐式引用,所以内部类可以直接访问外围类的外围类的域,包括私有的,这是内部类的访问特权,所以比常规 ...

  10. 谈谈MySQL数据表的类型(转)

    谈谈MySQL数据表的类型 通常意义上,数据库也就是数据的集合,具体到计算机上数据库可以是存储器上一些文件的集合或者一些内存数据的集合. 我们通常说的MySql数据库,sql server数据库等等其 ...