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. CSS的继承性和层叠性

    1.继承性 比不是所有的属性都能继承,只有一些文本的属性才能被继承.比如:color,text-开头的,line-开头的,font-开头的.这几种属性才能被继承. 其余的关于盒子,定位,布局的都不能被 ...

  2. hibernate---关联关系的 crud_cascade_fetch

    CRUD怎么写?? 存user信息, 自动存group信息 user.java package com.bjsxt.hibernate; import javax.persistence.Cascad ...

  3. (简单) POJ 2240 Arbitrage,SPFA。

    Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit o ...

  4. (简单) HDU 2612 Find a way,BFS。

    Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Nin ...

  5. 用C语言写一个“事件”的模拟程序

    源:用C语言写一个“事件”的模拟程序 Example.c //定义一个函数指针 func int (*func) (void); //调用该函数相当于触发了事件. //该事件触发后,会检查函数指针fu ...

  6. HUST 1371 Emergency relief

    状态压缩. 每一个人所需的物品对应一个数字,统计一个每个数字有几个.每一种提供物品的状态也对应一个数字,然后暴力判断. #include<cstdio> #include<cstri ...

  7. 文本去重-----awk或者uniq

    对于awk '!a[$3]++',需要了解3个知识点 1.awk数组知识,不说了 2.awk的基本命令格式 awk 'pattern{action}'     省略action时,默认action是{ ...

  8. HUST 1600 Lucky Numbers

    暴力打表. #include<cstdio> #include<cstring> #include<cmath> #include<string> #i ...

  9. Matlab笔记

    提取RGB分量,并显示出来 rgb=imread('mao.jpg'); rgb_r=rgb(:,:,); rgb_g=rgb(:,:,); rgb_b=rgb(:,:,); zero=zeros(, ...

  10. IOS开发-UI学习-delegate(代理)的使用,键盘消失

    代理是IOS开发中用到的一种设计模式.今天做了一个代理的小练习: 以下项目实现了两个页面之间的相互切换,并且在切换页面的时候完成了从一个页面往另一个页面的传值.从主页面往其他页面传值是容易的,但是反过 ...