题目

传送门:QWQ

分析

数位dp

状压一下现在的$ O(nlogn) $的$ LIS $的二分数组

数据小,所以更新时直接暴力不用二分了。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
ll dp[maxn][<<][];int k,digit[maxn];
int nextstate(int state,int x){
for(int i=x;i<;i++){
if(state&(<<i)){
state^=(<<i); break;
}
}
return (state|(<<x));
}
int getnum(int x){
int ans=;
while(x){
if(x&) ans++;
x>>=;
}
return ans;
}
ll dfs(int pos,int state,int leadingzero,int border){
if(pos==) return getnum(state)==k;
if(!leadingzero && !border && dp[pos][state][k]!=-) return dp[pos][state][k];
ll ans=;
int end=border?digit[pos]:;
for(int i=;i<=end;i++){
if(i== && leadingzero) ans+=dfs(pos-,state,,border&&i==end);
else ans+=dfs(pos-,nextstate(state,i),,border&&i==end);
}
if(!leadingzero&&!border) dp[pos][state][k]=ans;
return ans;
}
ll cal(ll n){
int pos=;
while(n){
digit[++pos]=n%; n/=;
}
return dfs(pos,,,);
}
int main(){
int t;ll l,r; cin>>t;
memset(dp,-,sizeof(dp));
for(int i=;i<=t;i++){
cin>>l>>r>>k;
cout<<"Case #"<<i<<": "<<cal(r)-cal(l-)<<endl;
}
return ;
}
/*
100
1234567 123456789012 8
5678567890101 1234567890123456 9
*/

【HDU】4352 XHXJ's LIS(数位dp+状压)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. hdu 4352 XHXJ's LIS 数位DP

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

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

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

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

随机推荐

  1. php 添加时间戳

    <?php $tomorrow = mktime(,,,date(,date("Y")); echo "Tomorrow is ".date(" ...

  2. Oracle10g客户端链接服务端配置

    Oracle10g客户端工具plsql链接服务端配置 Oracle10g客户端工具比如plsql,在网络中链接服务端问题比较多中国菜刀,经常出现很多莫名其妙的问题.实际上不是plsql的配置,问题还是 ...

  3. LeetCode 40

    // 既然不能重复利用,就在递归中选择下一个数,不能重复的话,就用setclass Solution { public: vector<vector<int>> combina ...

  4. 出错的sql

    alter table m_account  AUTO_INCREMENT=200029860;

  5. Xcode8出现问题总结

    上点干货,目前得知的一些bug解决汇总:iOS10相册相机闪退bughttp://www.jianshu.com/p/5085430b029fiOS 10 因苹果健康导致闪退 crashhttp:// ...

  6. bzoj3393

    题解: spfa 允许多次进队 代码: #include<bits/stdc++.h> using namespace std; struct que{int x,y,dire,dist; ...

  7. 记录Tomcat8.5文件上传,文件权限无法访问

    部署一个服务,文件上传本地可以,但是在Linux上通过docker发布到容器上,文件上传后,没有权限访问,查了好久才发现是Tomcat8.5的问题,低版本没有这个问题,现记录下. tomcat/bin ...

  8. python 发送QQ邮件的小例子

    首先QQ邮件用第三方客户端发送要申请验证码.而不是QQ的密码. 授权码就是你接下来登录要使用的密码 那么剩下的工作就很简单了.附简单代码如下: #coding:utf-8 import smtplib ...

  9. SharePoint 2013的100个新功能之搜索(一)

    一:新的搜索架构 SharePoint 2013中将最好的两个搜索引擎"SharePoint搜索"和"SharePoint FAST搜索服务"整合到了一个搜索引 ...

  10. REST风格

    1)Representational State Transfer,表述性状态转移,是一种软件架构风格 2)实现步骤 第一步:修改URL 例:http://localhost:8090/SMBMS_C ...