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;
    }
    

      

  • 相关阅读:
    传统神经网络所存在的问题
    Xcode 全局搜索中文的正则表达式
    ES2020可选链"?."
    ng : 无法将“ng”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
    阿里云盾反爬虫(Anti-Bot)产品方案浅析
    使用spring连接mysql数据库出错
    Win10 cmd的ssh命令连接linux虚拟机
    python不换行输出
    计算机网络-CSMA/CD
    计算机网络-奈氏准则
  • 原文地址:https://www.cnblogs.com/rolight/p/3891132.html
Copyright © 2011-2022 走看看