HDU - 3652 HDU - 3652 (数位DP&记忆化dfs)
2016-05-17 22:39
288 查看
HDU - 3652
B-number
SubmitStatus
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
Hint
Source
2010 Asia Regional Chengdu Site —— Online Contest
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
Hint
Source
2010 Asia Regional Chengdu Site —— Online Contest
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int dp[20][20][3]; int bit[20]; int dfs(int pos,int pre,int h,bool f) { if(pos==-1) return h==2&&pre==0; if(!f&&dp[pos][pre][h]!=-1) return dp[pos][pre][h]; int mm=f?bit[pos]:9; int ans=0; for(int i=0;i<=mm;i++) { int npre=(pre*10+i)%13; int nh=h; if(h==0&&i==1) nh=1; else if(h==1&&i!=1) nh=0; if(h==1&&i==3) nh=2; ans+=dfs(pos-1,npre,nh,f&&i==mm); } if(!f) dp[pos][pre][h]=ans; return ans; } int solve(int n) { int len=0; while(n) { bit[len++]=n%10; n/=10; } return dfs(len-1,0,0,1); } int main() { int n; memset(dp,-1,sizeof(dp)); while(scanf("%d",&n)!=EOF) { printf("%d\n",solve(n)); } return 0; }
相关文章推荐
- 基于WEB的企业用能信息在线填报系统设计--毕业设计论文
- hdu4824 双调TSP问题
- 《jQuery从入门到精通》目录
- Intellij IDEA连接Git 适用于新建项目 + 适用于已有项目
- iOS开发-进阶:JS与OC的交互
- LVS-NAT基于NFS存储部署Discuz
- java是怎么操作xml的-sax解析
- 将Web应用性能提高十倍的10条建议
- 欢迎使用CSDN-markdown编辑器
- Asp.Net MVC4入门指南(1): 入门介绍
- php,常见的面试
- Mysql的内存优化
- phpstorm8.0.3实现“识别tp中D方法的模型类”
- 类-Class
- 《jQuery从入门到精通》前言
- 使用apktool工具遇到could not decode arsc file的解决办法
- 汉诺塔求解
- .NET Framework 4.0 以上版本 下载地址
- js基础例子购物车升级版(未优化版)
- 内容提供者ContentProvider和内容解析者ContentResolver