HDU 3652 B-number 数位dp
2016-04-28 18:49
337 查看
G - B-number
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
3652
Appoint description:
System Crawler (2016-04-22)
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 flag表示状态 mod判断是否能整除
ACcode:
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
3652
Appoint description:
System Crawler (2016-04-22)
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 flag表示状态 mod判断是否能整除
ACcode:
#include <iostream> #include <cstdio> #include <cstring> #define ll long long using namespace std; int dp[25][25][3]; int date[25]; int dfs(int pos,int mod,int flag,bool limit){ if(!pos)return mod==0&&flag==2; if(!limit&&dp[pos][mod][flag]!=-1)return dp[pos][mod][flag]; int ret=0; int ed=limit?date[pos]:9; for(int i=0;i<=ed;i++){ int tmp=flag; int modd=(mod*10+i)%13; if(flag==1&&i==3) tmp=2; else if(flag==0&&i==1) tmp=1; else if(flag==1&&i!=1&&i!=3) tmp=0; ret+=dfs(pos-1,modd,tmp,limit&&i==ed); } return limit?ret:dp[pos][mod][flag]=ret; } void doit(int n){ int len=0; while(n){ date[++len]=n%10; n/=10; } printf("%d\n",dfs(len,0,0,1)); } int main(){ int n;memset(dp,-1,sizeof(dp)); while(~scanf("%d",&n))doit(n); }
相关文章推荐
- 重用字体字号对照
- UIViewContentMode 图文解说
- Linux下使Shell 命令脱离终端在后台运行
- myclipse的使用及其数据库的连接
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(九)
- C++实现读取特定路径下文件夹及文件名的方法
- maven 学习---Maven启用代理访问
- 王高利:中国Linux开源镜像站大全
- linux shell判断程序是否运行,没有运行则运行程序
- android 重写GridView,让子View能够按指定的大小展示
- HTML5标签二
- js动态创建表格方法
- C# 扩展
- Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfile or
- Bean的生命周期
- Asp.net 图片的两种处理方式
- .net ashx Session 未将对象引用到实例
- 使用MongoDB 记录业务日志
- 传智播客C++第5期 3-2:QSqlTableModel
- zabbix3.0.2安装grafana