HDU - 4352 - XHXJ's LIS(数位DP)
链接:
https://vjudge.net/problem/HDU-4352
题意:
a 到 b中一个数组成递增子序列长度等于k的数的个数
思路:
因为只有10个数,使用二进制维护一个递增序列,每次更新在注释写了。
然后正常的数位DP,
Dp(i, j, k),i是位置,j是当前的递增状态,k是长度。
考虑一下前缀0,重置状态
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
const int MAXN = 1e6+10;
LL F[30][1<<10][11];
int dig[30];
LL a, b;
int k;
int Upd(int x, int s)
{
//x表示当前值,s表示递增序列
for (int i = x;i < 10;i++)
{
if (s & (1<<i))
return (s ^ (1 << i)) | (1 << x);//找到一个比当前值大的,换成较小的
}
return s | (1 << x);
}
int Len(int x)
{
int cnt = 0;
while(x)
{
if (x&1)
cnt++;
x >>= 1;
}
return cnt;
}
LL Dfs(int pos, int sta, bool zer, bool lim)
{
if (pos == -1)
return Len(sta) == k;
if (!lim && F[pos][sta][k] != -1)
return F[pos][sta][k];
int up = lim ? dig[pos] : 9;
LL cnt = 0;
for (int i = 0;i <= up;i++)
cnt += Dfs(pos-1, (zer && i == 0) ? 0 : Upd(i, sta), zer && (i == 0), lim && (i == up));
if (!lim)
F[pos][sta][k] = cnt;
return cnt;
}
LL Solve(LL x)
{
int p = 0;
while(x)
{
dig[p++] = x%10;
x /= 10;
}
return Dfs(p-1, 0, true, true);
}
int main()
{
// freopen("test.in", "r", stdin);
memset(F, -1, sizeof(F));
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
scanf("%lld%lld%d", &a, &b, &k);
printf("Case #%d: %lld\n", ++cnt, Solve(b)-Solve(a-1));
}
return 0;
}
HDU - 4352 - XHXJ's LIS(数位DP)的更多相关文章
- HDU 4352 XHXJ's LIS 数位dp lis
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...
- hdu 4352 XHXJ's LIS 数位dp+状态压缩
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others ...
- HDU.4352.XHXJ's LIS(数位DP 状压 LIS)
题目链接 \(Description\) 求\([l,r]\)中有多少个数,满足把这个数的每一位从高位到低位写下来,其LIS长度为\(k\). \(Solution\) 数位DP. 至于怎么求LIS, ...
- HDU 4352 XHXJ's LIS (数位DP+LIS+状态压缩)
题意:给定一个区间,让你求在这个区间里的满足LIS为 k 的数的数量. 析:数位DP,dp[i][j][k] 由于 k 最多是10,所以考虑是用状态压缩,表示 前 i 位,长度为 j,状态为 k的数量 ...
- $HDU$ 4352 ${XHXJ}'s LIS$ 数位$dp$
正解:数位$dp$+状压$dp$ 解题报告: 传送门! 题意大概就是港,给定$[l,r]$,求区间内满足$LIS$长度为$k$的数的数量,其中$LIS$的定义并不要求连续$QwQ$ 思路还算有新意辣$ ...
- hdu 4352 XHXJ's LIS 数位DP+最长上升子序列
题目描述 #define xhxj (Xin Hang senior sister(学姐))If you do not know xhxj, then carefully reading the en ...
- hdu 4352 XHXJ's LIS 数位DP
数位DP!dp[i][j][k]:第i位数,状态为j,长度为k 代码如下: #include<iostream> #include<stdio.h> #include<a ...
- 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 ...
- HDU 4352 XHXJ's LIS ★(数位DP)
题意 求区间[L,R]内满足各位数构成的数列的最长上升子序列长度为K的数的个数. 思路 一开始的思路是枚举数位,最后判断LIS长度.但是这样的话需要全局数组存枚举的各位数字,同时dp数组的区间唯一性也 ...
- hdu 4352 XHXJ's LIS(数位dp+状压)
Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefull ...
随机推荐
- 爬虫解析库beautifulsoup
一.介绍 Beautiful Soup是一个可以从HTML或XML文件中提取数据的python库. #安装Beautiful Soup pip install beautifulsoup4 #安装解析 ...
- golang面对接口
- python线程(转)
转自:https://www.cnblogs.com/huxi/archive/2010/06/26/1765808.html
- postgres 序列
postgres序列(serial)和类型:https://www.cnblogs.com/alianbog/p/5654604.html 序列:https://www.cnblogs.com/mch ...
- nginx配置http静态站点服务器
1. 系统环境Windows 10 2. 设置静态站点目录,注意不要出现中文(这里踩了很多坑,可以查看错误日志error.log, “No mapping for the Unicode char ...
- 【CH1809】匹配统计(KMP)
题目链接 摘自https://www.cnblogs.com/wyboooo/p/9829517.html 用KMP先求出以a[i]为结尾的前缀与b匹配的最长长度. 比如 f[i] = j,就表示a[ ...
- JS权威指南读书笔记(五)
第十三章 Web浏览器中的JavaScript 1 在Html文档中嵌入客户端4种JS代码方法 a 内联方式,放置在<script>标签之间 b 放置在<script ...
- DDL 操作数据库
DDL 操作数据库:常用的操作 CRUD 一.C(create)创建 1.创建数据库 create database 数据库名称; 2.创建数据库,判断是否存在,再创建(如果存在,就不再创建) cre ...
- 如何在SAP UI5应用里添加使用摄像头拍照的功能
昨天Jerry的文章 纯JavaScript实现的调用设备摄像头并拍照的功能 介绍了纯JavaScript借助WebRTC API来开发支持调用设备的摄像头拍照的web应用.而我同事遇到的实际情况是, ...
- 浅析MySQL使用 GROUP BY 分组聚合与细分聚合
原创文章,转载请注明出处:http://www.cnblogs.com/weix-l/p/7521278.html: 若有错误,请评论指出,谢谢! 1. 聚合函数(Aggregate Function ...