链接:

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)的更多相关文章

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

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

  2. 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 ...

  3. HDU.4352.XHXJ's LIS(数位DP 状压 LIS)

    题目链接 \(Description\) 求\([l,r]\)中有多少个数,满足把这个数的每一位从高位到低位写下来,其LIS长度为\(k\). \(Solution\) 数位DP. 至于怎么求LIS, ...

  4. HDU 4352 XHXJ's LIS (数位DP+LIS+状态压缩)

    题意:给定一个区间,让你求在这个区间里的满足LIS为 k 的数的数量. 析:数位DP,dp[i][j][k] 由于 k 最多是10,所以考虑是用状态压缩,表示 前 i 位,长度为 j,状态为 k的数量 ...

  5. $HDU$ 4352 ${XHXJ}'s LIS$ 数位$dp$

    正解:数位$dp$+状压$dp$ 解题报告: 传送门! 题意大概就是港,给定$[l,r]$,求区间内满足$LIS$长度为$k$的数的数量,其中$LIS$的定义并不要求连续$QwQ$ 思路还算有新意辣$ ...

  6. hdu 4352 XHXJ's LIS 数位DP+最长上升子序列

    题目描述 #define xhxj (Xin Hang senior sister(学姐))If you do not know xhxj, then carefully reading the en ...

  7. hdu 4352 XHXJ's LIS 数位DP

    数位DP!dp[i][j][k]:第i位数,状态为j,长度为k 代码如下: #include<iostream> #include<stdio.h> #include<a ...

  8. 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 ...

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

    题意 求区间[L,R]内满足各位数构成的数列的最长上升子序列长度为K的数的个数. 思路 一开始的思路是枚举数位,最后判断LIS长度.但是这样的话需要全局数组存枚举的各位数字,同时dp数组的区间唯一性也 ...

  10. hdu 4352 XHXJ's LIS(数位dp+状压)

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

随机推荐

  1. Nvidia Jetson TX2开发板学习历程(1)- 详细开箱、上电过程

    考试周已经结束了,开发板也已经到了.希望借着这个假期能够好好的利用这块开发板学习Linux系统以及Tensorflow的相关知识. 我打算将学习历程通过博客的方式写出来,作为自己的笔记,也可以供以后拿 ...

  2. Python模拟知乎登录

    # -*- coding:utf-8 -*- import urllib import urllib2 import cookielib import time from PIL import Ima ...

  3. git 学习笔记 ---远程仓库

    Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上.怎么分布呢?最早,肯定只有一台机器有一个原始版本库,此后,别的机器可以“克隆”这个原始版本库,而且每台机器的版本库其实都是一样的, ...

  4. Spring主要用到两种设计模式

    Spring主要用到两种设计模式 1.工厂模式 Spring容器就是实例化和管理全部Bean的工厂. 工厂模式可以将Java对象的调用者从被调用者的实现逻辑中分离出来. 调用者只关心被调用者必须满足的 ...

  5. Description Resource Path Location Type Unknown Unknown Unknown org.eclipse.core.internal.resources.Marker is not of a displayable type

    是访问限制报错. 方法一: 全局属性Project>preferences>java>Compiler>Errors/Warnings>把右侧的[Deprecated a ...

  6. javascript高级程序设计阅读总结

    5章 引用类型 1.object类型 创建 1.var obj ={} ---对象字面量 2.var obj = new Object(); ---new操作符 2.Array类型 创建 1.var ...

  7. Fortify漏洞之Denial of Service: Regular Expression

    继续对Fortify的漏洞进行总结,本篇主要针对  Denial of Service: Regular Expression  漏洞进行总结,如下: 1.Denial of Service: Reg ...

  8. LeetCode算法01 Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  9. springBoot集成Redis,RedisTmple操作redis和注解实现添加和清空缓存功能

    配置 maven项目进入相关配置 <dependency>    <groupId>org.springframework.boot</groupId>    &l ...

  10. GC是如何判断一个对象为"垃圾"的?被GC判断为"垃圾"的对象一定会被回收吗?

    一.GC如何判断一个对象为”垃圾”的java堆内存中存放着几乎所有的对象实例,垃圾收集器在对堆进行回收前,第一件事情就是要确定这些对象之中哪些还“存活”着,哪些已经“死去”.那么GC具体通过什么手段来 ...