博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu3652——B-number(数位dp变形)
阅读量:2343 次
发布时间:2019-05-10

本文共 1449 字,大约阅读时间需要 4 分钟。

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

加了一个还要被13整除的条件,那就在状态数组多加一项表示被13整除的情况,当这项等于0说明能被13整除

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 10000000005#define Mod 10001using namespace std;int dight[30],dp[30][3][13];int dfs(int pos,int s,bool limit,int mod){ if(pos==0) return s==2&&mod==0; if(!limit&&dp[pos][s][mod]!=-1) return dp[pos][s][mod]; int end,ret=0; if(limit) end=dight[pos]; else end=9; for(int d=0;d<=end;++d) { int have=s,nmod=(mod*10+d)%13; if(s==1&&d==3) have=2; if(s==0&&d==1) have=1; if(s==1&&d!=1&&d!=3) have=0; ret+=dfs(pos-1,have,limit&&d==end,nmod); } if(!limit) dp[pos][s][mod]=ret; return ret;}int solve(int a){ memset(dight,0,sizeof(dight)); int cnt=1; while(a!=0) { dight[cnt++]=a%10; a/=10; } return dfs(cnt-1,0,1,0);}int main(){ memset(dp,-1,sizeof(dp)); int n; while(~scanf("%d",&n)) { printf("%d\n",solve(n)); } return 0;}

转载地址:http://uvcvb.baihongyu.com/

你可能感兴趣的文章
进程与线程的区别与联系、进程与线程的通信方式
查看>>
C++与C的区别
查看>>
产生死锁的必要条件及处理方法
查看>>
TCP和UDP的区别
查看>>
事务具有四个特性
查看>>
Hadoop Hdfs 配置
查看>>
tsung集群测试
查看>>
oracle定时删除表空间的数据并释放表空间
查看>>
解决文件提示: /bin/ksh^M: bad interpreter: bad interpreter:No such file or directory
查看>>
ajaxanywhere jsp 使用
查看>>
jquery的使用
查看>>
如何静态化JSP页面
查看>>
XML 与 Java 技术: 用 Castor 进行数据绑定
查看>>
Python未知领域系列:(附Python学习教程+Python学习路线)Python高级教程之面向对象
查看>>
盘点Python 面向对象编程最容易被忽视的知识点
查看>>
Python:一个可以套路别人的python小程序
查看>>
用Python告诉你:这些年,我们点过的的那些外卖
查看>>
如何美观地打印Python对象?这个标准库可以简单实现
查看>>
写作路上的这些小成绩,铸就了一个不平庸的程序员
查看>>
程序员找工作的个人经验教训以及注意事项
查看>>