HDU 2089 不要62 Posted on 2016-08-29 | In ACM | | Visitors 题目链接HDU 2089 题目类型:数位DP 题目分析题目大意统计区间[l, r]内,数字中不含4和62的数字个数 解析参考HDU 3555的题解 代码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <string>#include <vector>#include <iomanip>#include <bitset>#include <cstring>#include <iostream>#include <iosfwd>#include <deque>#include <algorithm>#define Memset(a,val) memset(a,val,sizeof(a))#define PI acos(-1.0)#define PB push_back#define MP make_pair#define rt(n) (i == n ? '\n' : ' ')#define hi printf("Hi----------\n")#define debug(x) cout<<"Debug : ---"<<x<<"---"<<endl;#define debug2(x,y) cout<<"Debug : ---"<<x<<" , "<<y<<"---"<<endl;#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;typedef pair<int,int> PII;typedef long long ll;const int maxn=500+5;const int mod=1000000007;const int INF=0x3f3f3f3f;const double eps=1e-8;ll dp[25][10][2];ll num[25];ll dfs(int pos,int pre,int status, bool limit){ if (pos < 1) { return status; } if (!limit&&dp[pos][pre][status]!=-1) { return dp[pos][pre][status]; } int mx = limit ? num[pos] : 9; ll ret = 0; for (int i=0; i<=mx; i++) { ret += dfs(pos - 1, i, status||(i==4)||(pre==6&&i==2), limit&&i==mx); } if (!limit) { dp[pos][pre][status] = ret; } return ret;}ll solve(ll n){ Memset(dp, -1); int pos = 0; ll tmp = n; while (tmp) { num[++pos] = tmp % 10; tmp /= 10; } return n - dfs(pos, 0, 0, 1);}int main(){ ll n,m; while (scanf("%lld%lld",&n,&m),n+m) { cout<<solve(m) - solve(n-1)<<endl; }}