【HDU2089】不要62(数位DP入门题)
2018-02-19 20:27
344 查看
Description
给定mm,nn,求mm到nn的所有整数中及不含’4’也不含’62’的数的个数。Solution
直接数位DP即可。。。Source
/**************************** * Au: Hany01 * Prob: [HDU2089] 不要62 * Date: Feb 19th, 2018 * Email: hany01@foxmail.com ****************************/ #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; #define rep(i , j) for (int i = 0 , i##_end_ = j; i < i##_end_ ; ++ i) #define For(i , j , k) for (int i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i) #define Fordown(i , j , k) for (int i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i) #define Set(a , b) memset(a , b , sizeof(a)) #define SZ(a) ((int)(a.size())) #define ALL(a) a.begin(), a.end() #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define INF (0x3f3f3f3f) #define INF1 (2139062143) #define Mod (1000000007) #define y1 wozenmezhemecaia #ifdef hany01 #define debug(...) fprintf(stderr , __VA_ARGS__) #else #define debug(...) #endif inline void File() { #ifdef hany01 freopen("hdu2089.in" , "r" , stdin); freopen("hdu2089.out" , "w" , stdout); #endif } template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; } inline int read() { register char c_; register int _ , __; for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1; for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48); return _ * __; } const int maxl = 9; int dp[maxl][2], cnt, a[maxl]; int dfs(int pos, int pre, int sta, int lmt) //'pre' stands for the last number, 'sta' stands for whether the last number is '6'. { if (!pos) return 1; if (!lmt && dp[pos][sta] >= 0) return dp[pos][sta]; register int tmp = 0; For(i, 0, lmt ? a[pos] : 9) if ((pre != 6 || i != 2) && i != 4) tmp += dfs(pos - 1, i, i == 6, lmt && i == a[pos]); if (!lmt) dp[pos][sta] = tmp; return tmp; } inline int Solve(int t) { cnt = 0; while (t) a[++ cnt] = t % 10, t /= 10; return dfs(cnt, -1, 0, 1); } int main() { File(); register int n, m; Set(dp, -1); while (n = read(), m = read(), n || m) printf("%d\n", Solve(m) - Solve(n - 1)); return 0; }
相关文章推荐
- HDU2089不要62(数位DP入门)
- hdu2089 不要62--数位dp入门题
- HDU2089 - 不要62 【数位dp的入门题】
- HDU2089 不要62(数位dp入门)
- HDU2089 不要62 (数位DP入门)
- hdu2089 不要62(数位dp入门)
- HDU2089 不要62(数位DP入门经典题目)
- HDU2089 不要62(数位DP入门经典题目)
- hdu2089:不要62(数位dp入门)
- 数位dp入门 hdu2089 不要62
- hdu2089不要62 (数位dp入门题)
- [hdu2089]不要62(数位dp)
- hdu 2089 不要62(数位dp入门)
- 【数位DP】HDU2089 不要62
- HDU 2089 不要62 数位DP入门
- [您有新的未分配科技点]数位dp:从懵X到板子(例题:HDU2089 不要62)
- HDU 2089 不要62 (数位DP,入门)
- HDU2089[不要62]--数位DP
- HDU 3555 Bomb + HDU 2089 不要62 数位dp入门题目
- hdu 2089 不要62(数位dp入门)