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 ...
随机推荐
- LeetCode | 152. 乘积最大子序列
原题(Medium): 给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数). 思路: 遍历数组时且逐元素相乘时,如果遇到了0,在求乘积最大值的情况下,0左边的元素 ...
- 使用while循环来处理列表和字典——参考Python编程从入门到实践
1. 在列表之间移动元素 unconfirmed_users = ['alice', 'brian', 'candace'] confirmed_users = [] # 验证每个用户,知道没有未验证 ...
- XGBoost对波士顿房价进行预测
import numpy as np import matplotlib as mpl mpl.rcParams["font.sans-serif"] = ["SimHe ...
- xorm -Alias,Asc,Desc方法实例
Alias(string)给Table设定一个别名 package main import ( "fmt" _ "github.com/go-sql-driver/mys ...
- prometheus+alertmanager+granafa监控总结,安装基于docker-compose(长期更新)
最近自己个人尝试在使用prometheus+grafana监控工作业务上的指标, 但是报警功能还没有实际用上,但是感觉是很好用,写下一些啃prometheus官网文档并且自己用到的一些配置的总结,后续 ...
- Ubuntu下载搜狗输入法
实在...因为百度上写的就很好了,所以这里就直接“链”了.. https://jingyan.baidu.com/article/2d5afd6933a67b85a2e28e9f.html
- java.lang.IllegalArgumentException: Expected authority at index 7: http:// 异常的原因
今天遇到个错误,异常信息 java.lang.IllegalArgumentException: Expected authority at index 7: http:// ,中文意思就是说参数 ...
- 3D星形贴图
3D星形贴图: /** * * *---------------------* * | *** 3D星形贴图 *** | * *---------------------* * * 编辑修改收录:fe ...
- 1)NET CORE 重新认识 .net & .net core
最近想系统性的学习下.net core ,在这之前我想再重新的认识下.net ,以及跟.net core 的区别. 有些我们开发.net经常用到的词汇可能还不是很了解,或者不能清晰的出他们的关系与却别 ...
- oracle 查询 10题
说明:表数据来自oracle 初始用户之一scott里面的三个初始表:emp,dept,salgrade --1.查询员工表中工资最高的雇员的员工号.员工姓名.工资和部门号. select empno ...