zoukankan      html  css  js  c++  java
  • hdu 2089 数位dp入门

    HDU 2089

    题意:中文题

    思路:数位dp入门题

    AC代码:

    #include "iostream"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #pragma comment(linker, "/STACK:102400000,102400000")
    #define ll long long
    #define endl ("
    ")
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a,x) memset(a,x,sizeof(a))
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    #define ft (frist)
    #define sd (second)
    #define lrt (rt<<1)
    #define rrt (rt<<1|1)
    using namespace std;
    const long long INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const int N=1e3+100;
    const ll mod=1e9+7;
    
    int bit[20],dp[20][2];
    
    int dfs(int pos, int pre, bool f, bool limit){
        if(pos==0) return 1;
        int up=limit?bit[pos]:9;
        if(!limit && dp[pos][f]!=-1) return dp[pos][f];
        int ret=0;
        for(int i=0; i<=up; ++i){
            if(i==4) continue;
            if(i==2 && pre==6) continue;
            ret+=dfs(pos-1, i, i==6, limit && i==bit[pos]);
        }
        if(!limit) dp[pos][f]=ret;
        return ret;
    }
    
    int solve(int x){
        int t=0;
        while(x>0){
            bit[++t]=x%10;
            x/=10;
        }
        return dfs(t, -1, 0, 1);
    }
    
    int main(){
        ll l,r; mem(dp,-1);
        while(cin>>l>>r && l&&r){
            cout<<solve(r)-solve(l-1)<<endl;
        }
        return 0;
    }
  • 相关阅读:
    题解 【洛谷】AT654
    题解【洛谷】CF134A
    jquery中select的应用
    Linq to xml 小例
    mongodb 使用场景和不使用场景
    一个面试题的解答-----从500(Id不连续)道试题库里随机抽取20道题!
    数据采集
    50款强力jquey,js 插件推荐
    node.js 学习
    wcf好文集合
  • 原文地址:https://www.cnblogs.com/max88888888/p/7406555.html
Copyright © 2011-2022 走看看