题意:给定一个区间,让你求在这个区间里的满足LIS为 k 的数的数量。

析:数位DP,dp[i][j][k] 由于 k 最多是10,所以考虑是用状态压缩,表示 前 i 位,长度为 j,状态为 k的数量有多少,再结合nlogn的LIS,

就能搞定这个题目了。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const LL mod = 1e9 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} LL dp[25][12][1200];
int a[25];
int k; LL dfs(int pos, int num, int s, bool is, bool ok){
if(!pos) return k == num;
if(num > k) return 0;
LL &ans = dp[pos][k][s];
if(!ok && ans >= 0) return ans; LL res = 0;
int n = ok ? a[pos] : 9;
for(int i = 0; i <= n; ++i){
if(is && !i) res += dfs(pos-1, num, s, is, ok && i == n);
else if((1<<i) > s) res += dfs(pos-1, num+1, s|(1<<i), is && !i, ok && i == n);
else if((1<<i)&s) res += dfs(pos-1, num, s, is && !i, ok && i == n);
else for(int j = i+1; j <= 9; ++j)
if((1<<j)&s){ res += dfs(pos-1, num, (s^(1<<j))|(1<<i), is && !i, ok && i == n); break; } }
if(!ok) ans = res;
return res;
} LL solve(LL n){
int len = 0;
while(n){
a[++len] = n % 10;
n /= 10;
}
return dfs(len, 0, 0, true, true);
} int main(){
memset(dp, -1, sizeof dp);
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
LL n, m;
scanf("%I64d %I64d %d", &m, &n, &k);
printf("Case #%d: %I64d\n", kase, solve(n) - solve(m-1));
}
return 0;
}

HDU 4352 XHXJ's LIS (数位DP+LIS+状态压缩)的更多相关文章

  1. HDU 4352 XHXJ&#39;s LIS(数位dp&amp;状态压缩)

    题目链接:[kuangbin带你飞]专题十五 数位DP B - XHXJ's LIS 题意 给定区间.求出有多少个数满足最长上升子序列(将数看作字符串)的长度为k. 思路 一个数的上升子序列最大长度为 ...

  2. HDU 4352 XHXJ's LIS 数位dp lis

    目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...

  3. hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)

    #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the entire ...

  4. Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  5. HDU 4352 - XHXJ's LIS - [数位DP][LIS问题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  6. HDU 4352 XHXJ's LIS HDU(数位DP)

    HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...

  7. hdu 4352 XHXJ's LIS (数位dp+状态压缩)

    Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully readin ...

  8. 【状态压缩DP】HDU 4352 XHXJ'S LIS

    题目大意 Vjudge链接 定义一个数的内部LIS长度表示这个数每个数位构成的序列的LIS长度,给出区间\([l,r]\),求区间内内部LIS长度为\(k\)的数的个数. 输入格式 第一行给出数据组数 ...

  9. [BZOJ 4455] [ZJOI 2016] 小星星 (树形dp+容斥原理+状态压缩)

    [BZOJ 4455] [ZJOI 2016] 小星星 (树形dp+容斥原理+状态压缩) 题面 给出一棵树和一个图,点数均为n,问有多少种方法把树的节点标号,使得对于树上的任意两个节点u,v,若树上u ...

随机推荐

  1. 20181104_C#线程之Thread_ThreadPool_使用Thread实现回到和带参数的回调

    C#   .net  Framework多线程演变路径: 1.0    1.1 时代使用Thread 2.0    时代使用ThreadPool 3.0    时代使用Task 4.0    时代使用 ...

  2. 经典的CNN网络模型概述

    接下来几天,将把自己最近读的关于图片分类的经典网络模型论文整理一遍.大概做个摘要.这些论文都是在imagenet上1.2 million数据训练出来的. 由于从这些预训练的网络训练的deep feat ...

  3. 查看Android内存,cpu

    转自https://testerhome.com/topics/2583 一.查看内存 查看Android应用内存: adb shell dumpsys meminfo 1.查看详细的内存: adb ...

  4. mysql导出数据库数据及表结构

    1,导出远程数据库数据到本地 mysql -A wj_sms -h192.168.1.105 -uroot -p4321 -ss -e "set NAMES 'utf8';SELECT * ...

  5. 推荐一篇mysql优化干货

    淘宝的技术一直比较前沿,特别是LVS的作者加入淘宝后,淘宝和阿里的开源做的有声有色,君不见淘宝出了tengine,tairs,tddl,hsf(soa框架,未开源),tfs(小文件存储系统)等等,阿里 ...

  6. js调用activeX插件 报异常:TypeError:对象不支持 属性方法

    部署之后的js网页如果调用没有签名的 ocx/dll 插件的话会报异常:TypeError:对象不支持 “init” 属性方法 (init为插件公开的方法) 但是如果写一个htm本地文件去调用插件,和 ...

  7. C++防止文件重复包含

    引用自:https://blog.csdn.net/xhfight/article/details/51550446 为了避免同一个文件被include多次,C/C++中有两种方式,一种是#ifnde ...

  8. shell编程——变量的数值计算

    在shell脚本中,有时候会需要对数值类型的变量进行计算,通常我们用的是(()) [root@localhost collect]# ((a=1+2)) [root@localhost collect ...

  9. flex 设置换行flex-wrap

    flex 设置flex-wrap 换行 本来预想的正常情况下,代码应该如下: ul { width: 100%; display: flex; flex-wrap: wrap; li { ; widt ...

  10. 配置siebel捕捉SQL语句

    C:\Siebel\15.0.0.0.0\Client\BIN\siebel.exe /c c:\Siebel\15.0.0.0.0\Client\bin\chs\siebel.cfg /B &quo ...