标签:
不要62
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
1 100 0 0
Sample Output
80
分析:数位dp基础题;
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, ls[rt] #define Rson mid+1, R, rs[rt] const int maxn=1e5+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} inline ll read() { ll x=0;int f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } int n,m,k,t,d[10],dp[10][2][2][10]; bool vis[10][2][2][10];//第几位,数是否符合要求,是否满足答案,当前位是多少; int dfs(int pos,int ca,int ok,int now) { if(pos<0)return ok; if(ca&&vis[pos][ca][ok][now])return dp[pos][ca][ok][now]; if(ca) { int&ret=dp[pos][ca][ok][now]; vis[pos][ca][ok][now]=true; for(int i=0;i<=9;i++) { if(ok) { ret+=dfs(pos-1,ca,ok,i); } else { if(i==4)ret+=dfs(pos-1,ca,1,4); else if(now==6&&i==2)ret+=dfs(pos-1,ca,1,2); else ret+=dfs(pos-1,ca,ok,i); } } return ret; } else { int ret=0; for(int i=0;i<=d[pos];i++) { if(ok) { ret+=dfs(pos-1,i<d[pos],ok,i); } else { if(i==4)ret+=dfs(pos-1,i<d[pos],1,4); else if(now==6&&i==2)ret+=dfs(pos-1,i<d[pos],1,2); else ret+=dfs(pos-1,i<d[pos],ok,i); } } return ret; } } int solve(int p) { memset(dp,0,sizeof(dp)); memset(vis,false,sizeof(vis)); int num=0; while(p) { d[num++]=p%10; p/=10; } return dfs(num-1,0,0,0); } int main() { int i,j; while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0)break; printf("%d\n",m-n+1-solve(m)+solve(n-1)); } //system("Pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5932161.html