B-number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5000    Accepted Submission(s): 2866

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
 
题意:
计算N以内的数中含有13并且能被13整除的数的个数
代码:
 /*
记忆化搜索+数位DP,不是很理解这一套路,dp[i][j][k],i表示位数,j表示余数,k=0表示没有13,k=1表示末尾是1,
k=2表示有13.一个数除以13可以是前几位除以13的余数连上后几位再除以13......
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
int n;
int dp[][][];
int c[];
int dfs(int lne,int mod,int have,int lim) //lim代表是否为上限
{
if(lne<=) //没有位数了返回符合的情况
return mod==&have==;
if(!lim&&dp[lne][mod][have]!=-) //没有上限并且已被访问过
return dp[lne][mod][have];
int num=lim?c[lne]:; //假设该位是2,下一位是3,如果现在算到该位为1,那么下一位是能取到9的,
//如果该位为2,下一位只能取到3
int ans=;
for(int i=;i<=num;i++)
{
int nmod=(mod*+i)%; //看是否能整除13,而且由于是从原来数字最高位开始算,
//事实上这个过程就是一个除法过程
int nhave=have;
if(have==&&i==) nhave=; //末尾不是1,现在加入的是1
if(have==&&i!=&&i!=) nhave=; //末尾是1,现在加入的不是1
if(have==&&i==) nhave=; //末尾是1,现在加入的是3
ans+=dfs(lne-,nmod,nhave,lim&&i==num); //lim&&i==num,在最开始,取出的num是最高位,
//所以如果i比num小,那么i的下一位都可以到达9,而i==num了,最大能到达的就只有,c[len-1]
}
if(!lim)
dp[lne][mod][have]=ans; //dp只记录没有限的值
return ans;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(dp,-,sizeof(dp));
int cnt=;
while(n)
{
c[++cnt]=n%;
n/=;
}
printf("%d\n",dfs(cnt,,,));
}
return ;
}

数位DP HDU3652的更多相关文章

  1. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...

  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. hdu3652(数位dp)

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

  5. HDU3652(数位dp)

    A - B-number Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descri ...

  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 数位dp记忆化搜索

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

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

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

随机推荐

  1. WPF标准控件模板查看程序(文件里面)

    xaml <Window x:Class="ControlTemplateBrowser.MainWindow" xmlns="http://schemas.mic ...

  2. 【MongoDB】3.详细命令集合

    [注意:MongoDB自动将_id字段设置为主键] -------------------------------------------------------------------------- ...

  3. HDU 3461 Code Lock(并查集)

    很好的一个题,思想特别6 题意:给你小写字母个数n,每个字母可以向上翻动,例如:d->c,a->z.然后给你m对数(L,R)(L<=R),表示[L,R]之间可以同时向上翻动,且翻动后 ...

  4. wpf中手风琴控件Accordion编辑模板后控件不正常。

    昨天有个网友Accordion控件从sl迁移到wpf时候显示不正常.也是就没有效果. 我也是sl做的比较多,wpf玩的少,Accordion模板里触发器,状态组调了一早上都没达到满意效果, 无奈只有百 ...

  5. 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake

    题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...

  6. oracle去重

    oracle去重 create table tmp_table3 as (SELECT seqno FROM (SELECT t.seqno,ROWID, ROW_NUMBER() OVER(PART ...

  7. HTML5属性运用

    HTML5 接触移动端,或专注于支持HTML5浏览器进行前端开发的工作者都不会陌生,这个已经普及很广,对于我专注于PC端开发的人来说,觉得陌生但又觉得很熟悉,大家都知道做PC前端开发为了兼容IE老版本 ...

  8. Code Rush插件

    code rush 是微软推出的一款VS2008上的插件.他有强大的文件和代码导航功能,易于访问的重构和代码创建功能.一组编辑器.选择.剪贴板工具等. 教程链接 http://www.devexpre ...

  9. The name does not exist in the namespace error in XAML

    方法1:In the solution property page, check the platform of the assembly that contains "UpdatingMe ...

  10. mac mysql

    http://blog.neten.de/posts/2014/01/27/install-mysql-using-homebrew/