zoukankan      html  css  js  c++  java
  • HDU 4352 XHXJ's LIS 数位DP + 状压

    由LIS的nlogn解法 可以得出最后统计数组中数的个数即为LIS的长度 这样就可以状压了

    #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;
    
    typedef long long LL;
    const int maxn = 20;
    LL a,b,k;
    int len = 0,lim[maxn];
    LL f[maxn][1 << 10][11];
    
    void getlim(LL n) {
        len = 0;
        memset(lim,0,sizeof(lim));
        while(n) {
            lim[len++] = n % 10; n /= 10;
        }
    }
    
    int check(int state) {
        int cnt = 0;
        while(state) {
            cnt += state & 1;
            state >>= 1;
        }
        return cnt;
    }
    
    int gao(int state,int num) {
        for(int i = num;i <= 9;i++) if(state & (1 << i)) {
            state &= ~(1 << i);
            break;
        }
        state |= (1 << num);
        return state;
    }
    
    LL dfs(int now,int state,int first,int bound) {
        if(now == 0) {
            if(check(state) == k) {
                return 1;
            }
            return 0;
        }
        LL &note = f[now][state][k];
        int m = bound ? lim[now - 1] : 9;
        if(!bound && first && note != -1) return note;
        LL ret = 0;
        for(int i = 0;i <= m;i++) {
            int ns = gao(state,i);
            if(i || first) ret += dfs(now - 1,ns,1,bound && i == m);
            else ret += dfs(now - 1,state,0,bound && i == m);
        }
        if(!bound && first) note = ret;
        return ret;
    }
    
    LL solve(LL num) {
        getlim(num);
        return dfs(len,0,0,1);
    }
    
    int main() {
        memset(f,-1,sizeof(f));
        int T,kase = 1;
        cin >> T;
        while(T--) {
            cout << "Case #" << kase++ << ":" << " ";
            cin >> a >> b >> k;
            cout << solve(b) - solve(a - 1) << endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    【ORA-02049】超时分布式事务处理等待锁 解决方法
    Git使用出错:Couldn‘t reserve space for cygwin‘s heap, Win32
    JS身份证号码校验
    linux 下查看cpu位数 内核等参数命令(转)
    linux ps命令,查看进程cpu和内存占用率排序(转)
    JAVA图片验证码
    JAVA BigDecimal 小数点处理
    Linux命令大全
    Eclipse Java注释模板设置详解
    JSONArray的应用
  • 原文地址:https://www.cnblogs.com/rolight/p/3891132.html
Copyright © 2011-2022 走看看