zoukankan      html  css  js  c++  java
  • HDU3555 Bomb(数位dp)

    我们遇到数位dp题要求含什么的,都把他转化为不含什么的,这样就跟不要62这道题一模一样了

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cstdio>
    #include<map>
    #include<string>
    #include<vector>
    using namespace std;
    typedef long long ll;
    const int N=2e5+5;
    ll f[21][10];
    void init(){
        int i;
        int j,k;
        for(i=0;i<=9;i++){
            f[1][i]=1;
        }
        for(i=2;i<20;i++){
            for(j=0;j<=9;j++){
                for(k=0;k<=9;k++){
                    if(j==4&&k==9)
                        continue;
                    f[i][j]+=f[i-1][k];
                }
            }
        }
    }
    ll dp(ll n){
        if(!n)
            return 0;
        vector<int> num;
        while(n){
            num.push_back(n%10);
            n/=10;
        }
        int i,j;
        ll res=0;
        ll last=0;
        for(i=num.size()-1;i>=0;i--){
            int x=num[i];
            for(j=0;j<x;j++){
                if(last==4&&j==9)
                    continue;
                res+=f[i+1][j];
            }
            if(x==9&&last==4)
                break;
            last=x;
            if(!i)
                res++;
        }
        return res;
    }
    int main(){
        int i;
        int t;
        cin>>t;
        init();
        while(t--){
            ll r;
            cin>>r;
            cout<<r-dp(r)+1<<endl;
        }
    }
    View Code
  • 相关阅读:
    hdu 1535 Invitation Cards(spfa)
    hdu 1317 XYZZY
    hdu 1245 Saving James Bond
    hdu 1546 Idiomatic Phrases Game
    hdu 1217 Arbitrage(佛洛依德)
    hdu 1599 find the mincost route(无向图的最小环)
    poj1579
    poj1905
    poj1384
    poj3624
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/12688171.html
Copyright © 2011-2022 走看看