zoukankan      html  css  js  c++  java
  • uestc250windy数数位dp

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <set>
    #include <queue>
    #include <stack>
    using namespace std;
    
    int dp[100][100][2];
    int up[1000];
    int ab(int x)
    {
        return x>0? x:-x;
    }
    
    int dfs(int pos,int top,int first,int flag)
    {
        if(pos<=0) return first==1;
        if(first&&!flag&&~dp[pos][top][first]) return dp[pos][top][first];
        int limit = flag? up[pos]: 9,ret=0;
        for(int i= 0;i<=limit;i++){ 
            int t= ab(top-i);  
            if(t>=2||!first) ret+=dfs(pos-1,i,first||i,flag&&(i==limit)); //这个判断是海哥告诉的,非常吊,自己品味。
        }
        return  flag? ret: dp[pos][top][first] = ret;
    }
    int solve(int x)
    {
        int len=0;
        while(x){
            up[++len]=x%10;
            x/=10;
        }
        return dfs(len,100,0,1);
    }
    int main()
    {
        memset(dp,-1,sizeof(dp));
        int n,m;
        while(scanf("%d%d",&n,&m)!=EOF){
            cout<<solve(m) - solve(n-1) <<endl;
        }
        return 0;
    }
  • 相关阅读:
    0919 作业
    0918 登录注册
    20190918 文件处理
    20190917 字符编码
    0916 作业
    0916 数据类型与深浅拷贝
    0913 作业
    0912 for循环及内置方法
    0911 作业
    Ubuntu同时忘记用户密码和root密码
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3896641.html
Copyright © 2011-2022 走看看