标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include <cstdio> #include <iostream> #include <cstring> #include <string> using namespace std; int a[10]; int dp[10][2][2]; int dfs(int u, bool is6, bool have, bool limit) { if(u < 1) return !have; if(!limit && dp[u][is6][have] != -1) return dp[u][is6][have]; int maxn = limit ? a[u] : 9; int ret = 0; for(int i=0; i<=maxn; i++) { ret += dfs(u-1, i==6, have||i==4||(is6&&i==2), limit&&i==maxn); } if(!limit) dp[u][is6][have] = ret; return ret; } int f(int n) { int len=0; while(n) { a[++len] = n%10; n /= 10; } return dfs(len, 0, 0, 1); } int main () { int n, m; memset(dp, -1, sizeof(dp)); while(scanf("%d%d", &n, &m) != EOF && (m|n)) { printf("%d\n", f(m) - f(n-1)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/AcIsFun/p/5389212.html