zoukankan      html  css  js  c++  java
  • 不要62(数位dp模板题)

     AC_Code:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <cmath>
     6 #include <queue>
     7 #include <stack>
     8 #include <vector>
     9 #include <set>
    10 #include <map>
    11 #include <algorithm>
    12 using namespace std;
    13 typedef long long ll;
    14 const int maxn=10;
    15 
    16 int dp[maxn][maxn][2];
    17 int a[maxn];
    18 int len;
    19 
    20 int dfs(int pos, int pre, int status, bool lead, bool limit){
    21     if( pos<1 ) return status;
    22     if((!limit)&&(!lead)&&dp[pos][pre][status]!=-1) return dp[pos][pre][status];
    23     int up=limit?a[pos]:9;
    24     int ans=0;
    25     for(int i=0;i<=up;i++){
    26         if( pre==6&&i==2 ) continue;
    27         else if( i==4 ) continue;
    28         ans += dfs(pos-1,i,1,(lead&&(!i)),limit&&(i==up));
    29     }
    30     return ((!limit)&&(!lead))?dp[pos][pre][status]=ans:ans;
    31 }
    32 
    33 int part(int x){
    34     len=0;
    35     while(x) a[++len]=x%10,x/=10;
    36     memset(dp,-1,sizeof(dp));
    37     return dfs(len,-1,1,1,1);
    38 }
    39 
    40 int main()
    41 {
    42     int n,m;
    43     while(~scanf("%d%d",&n,&m)){
    44         if( n==0&&m==0 ) break;
    45         else if( n==0 ) printf("%d
    ",part(m)-part(n)+1);
    46         else printf("%d
    ",(part(m)-part(n-1)));
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    Mac014--Sourcetree安装(Git client)
    SSM003/构建Maven单模块项目(二)
    Git016--Work
    Mac013--Docker安装
    前端002/常用标签属性(工作应用)
    Python 38 初识数据库
    Python 38 sql基础
    Python 39 数据库的数据类型
    Python 39 数据库
    Python 37 进程池与线程池 、 协程
  • 原文地址:https://www.cnblogs.com/wsy107316/p/12250028.html
Copyright © 2011-2022 走看看