题意:给定一个区间,让你求在这个区间里的满足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. 第二章 伪分布式安装hadoop hbase

    安装单机模式的hadoop无须配置,在这种方式下,hadoop被认为是一个单独的java进程,这种方式经常用来调试.所以我们讲下伪分布式安装hadoop. 我们继续上一章继续讲解,安装完先试试SSH装 ...

  2. netcore中使用log4net日志

    第一.控制台程序中使用log4net  static void Main(string[] args) { ILoggerRepository repository = LoggerManager.C ...

  3. ODPS基础

    遇到一个项目需求是统计128张分库分表的数据表记录的最大id,通过单表查询计算非常费时,也无法应对分表数更多的情况,因此考虑到通过odps进行任务发布和运算 在云端 http://d2.alibaba ...

  4. java.lang.NoClassDefFoundError: org/jaxen/JaxenException解决方法

    在使用dom4j的xpath时出现java.lang.NoClassDefFoundError: org/jaxen/JaxenException的异常,原因是dom4j引用了jaxen jar包,而 ...

  5. Linux6系统安装

  6. preprocess

    1,宏定义,有参宏,无参宏,宏定义实现的是定义一个符号常量; 条件编译3种方式,文件包含含义; 不带参数的宏定义;既用一个指定的的标识符来代替一个字符串; #define RUIY 10000000 ...

  7. 关于where和having的直观理解

    一,查询区别 where是对前面select的字段没有要求,直接查询库表的 having是对前面的select的字段有要求,字段已经select出来的 可以用having进行处理 select id, ...

  8. 微软TechNet关于TLS的细节的描述

    https://technet.microsoft.com/en-us/library/cc785811.aspx TLS协议太复杂了,RFC太长没时间看,这篇还可以,好歹知道个大概. 想知道全部细节 ...

  9. REST 规范

    DRF之REST规范介绍及View请求流程分析 DRF之解析器组件及序列化组件 DRF - 序列化组件(GET/PUT/DELETE接口设计).视图优化组件 DRF之权限认证频率组件 DRF之注册器响 ...

  10. VUE 初步学习

    Vue 简单的总结一 Vue 简单的总结二 Vue 简单的总结三 Vue 简单的总结四(项目流程) Vue 简单的总结五 Vue(6)- Vue-router进阶.单页面应用(SPA)带来的问题 Vu ...