题意:给定一个区间,让你求在这个区间里的满足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. 嵌入式Linux驱动和固件有何区别?供应商是如何用固件压缩成本的?

    作为一个驱动开发者, 你可能发现你面对一个设备必须在它能支持工作前下载固件到它里面. 硬件市场的许多地方的竞争是如此得强烈, 以至于甚至一点用作设备控制固件的 EEPROM 的成本制造商都不愿意花费. ...

  2. SpringMVC使用Hibernate-validator验证出现的错误

    缺少jar包 SpringMVC可以使用Hibernate-validator作为效验的实现,需要的jar包: hibernate-validator.jar validation-api.jar j ...

  3. 开始使⽤ZooKeeper的API

    在之前的章节中,我们使用zkCli工具介绍了ZooKeeper的基本操作.从本章开始,我们将会看到在应用中如何通过API来进行操作.首先介绍一下如何使用ZooKeeper的API进行开发,展示如何创建 ...

  4. winform中读取App.config中数据连接字符串

    1.首先要在工程引用中导入System.Configuration.dll文件的引用. 2.通过System.Configuration.ConfigurationManager.Connection ...

  5. 全面了解POI操作Microsoft Office(Word、Excel、PowerPoint)

    POI 与 Microsoft Office 1. POI 简介 POI 是 Apache 下的 Jakata 项目的一个子项目,主要用于提供 java 操作 Microsoft Office 办公套 ...

  6. vector(实现存图)

    #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #i ...

  7. Linux虚机密码破解

    1 重启机器,在机器读秒时按回车键 2 选择要启动的操作系统按 e 3 选择kernel所在行按 e 4 末尾输入空格  single 5 敲回车 在按 b 系统将进入单用户模式 然后 可以 通过 p ...

  8. 网卡流量监控脚本 ( Python )

    #!/usr/bin/env python # coding: utf-8 # author: Xiao Guaishou try: import psutil except ImportError: ...

  9. spring security的原理及教程

    spring security使用分类: 如何使用spring security,相信百度过的都知道,总共有四种用法,从简到深为:1.不用数据库,全部数据写在配置文件,这个也是官方文档里面的demo: ...

  10. Python_安装官方whl包和tar.gz包

    Windows环境: 安装whl包:pip install wheel    ->    pip install  **.whl 安装tar.gz包:cd到解压后路径,python setup. ...