HDU 4352 - XHXJ's LIS - [数位DP][LIS问题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
If you do
not know xhxj, then carefully reading the entire description is very
important.
As the strongest fighting force in UESTC, xhxj grew up in Jintang,
a border town of Chengdu.
Like many god cattles, xhxj has a legendary life:
2010.04, had not yet begun to learn the algorithm, xhxj won the second prize
in the university contest. And in this fall, xhxj got one gold medal and one
silver medal of regional contest. In the next year's summer, xhxj was invited to
Beijing to attend the astar onsite. A few months later, xhxj got two gold medals
and was also qualified for world's final. However, xhxj was defeated by
zhymaoiing in the competition that determined who would go to the world's
final(there is only one team for every university to send to the world's final)
.Now, xhxj is much more stronger than ever,and she will go to the dreaming
country to compete in TCO final.
As you see, xhxj always keeps a short
hair(reasons unknown), so she looks like a boy( I will not tell you she is
actually a lovely girl), wearing yellow T-shirt. When she is not talking, her
round face feels very lovely, attracting others to touch her face gently。Unlike
God Luo's, another UESTC god cattle who has cool and noble charm, xhxj is quite
approachable, lively, clever. On the other hand,xhxj is very sensitive to the
beautiful properties, "this problem has a very good properties",she always said
that after ACing a very hard problem. She often helps in finding solutions, even
though she is not good at the problems of that type.
Xhxj loves many games
such as,Dota, ocg, mahjong, Starcraft 2, Diablo 3.etc,if you can beat her in any
game above, you will get her admire and become a god cattle. She is very
concerned with her younger schoolfellows, if she saw someone on a DOTA platform,
she would say: "Why do not you go to improve your programming skill". When she
receives sincere compliments from others, she would say modestly: "Please don’t
flatter at me.(Please don't black)."As she will graduate after no more than one
year, xhxj also wants to fall in love. However, the man in her dreams has not
yet appeared, so she now prefers girls.
Another hobby of xhxj is
yy(speculation) some magical problems to discover the special properties. For
example, when she see a number, she would think whether the digits of a number
are strictly increasing. If you consider the number as a string and can get a
longest strictly increasing subsequence the length of which is equal to k, the
power of this number is k.. It is very simple to determine a single number’s
power, but is it also easy to solve this problem with the numbers within an
interval? xhxj has a little tired,she want a god cattle to help her solve this
problem,the problem is: Determine how many numbers have the power value k in
[L,R] in O(1)time.
For the first one to solve this problem,xhxj will upgrade
20 favorability rate。
every line has three positive integer
L,R,K.(0<L<=R<263-1 and 1<=K<=10).
which t is the number of the test case starting from 1 and ans is the
answer.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int K;
int dig[];
ll dp[][<<][]; ll getNewSta(ll sta,int num) //运用LIS问题的nlogn思想进行更新状态
{
for(int i=num;i<=;i++)
if(sta&(<<i)) return (sta^(<<i))|(<<num);
return sta|(<<num);
}
int get1cnt(ll sta) //获取状态sta中有多少个“1”
{
int cnt=;
while(sta)
{
cnt+=sta&;
sta>>=;
}
return cnt;
}
ll dfs(int pos,ll sta,bool lead,bool limit) //lead是前导零标记
{
if(pos==) return get1cnt(sta)==K; //精确到某一个数,判断其LIS的长度是否等于K
if(!limit && dp[pos][sta][K]!=-) return dp[pos][sta][K]; int up=limit?dig[pos]:;
ll ans=;
for(int i=;i<=up;i++)
ans+=dfs(pos-,(lead && i==)?:getNewSta(sta,i),lead && i==,limit && i==up); if(!limit) dp[pos][sta][K]=ans;
return ans;
}
ll solve(ll x)
{
int len=;
while(x)
{
dig[++len]=x%;
x/=;
}
return dfs(len,,,);
} int main()
{
int T;
scanf("%d",&T);
memset(dp,-,sizeof(dp));
for(int kase=;kase<=T;kase++)
{
ll L,R;
scanf("%I64d%I64d%d",&L,&R,&K);
printf("Case #%d: %I64d\n",kase,solve(R)-solve(L-));
}
}
HDU 4352 - XHXJ's LIS - [数位DP][LIS问题]的更多相关文章
- HDU 4352 XHXJ's LIS 数位dp lis
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...
- HDU 4352 XHXJ's LIS (数位DP+LIS+状态压缩)
题意:给定一个区间,让你求在这个区间里的满足LIS为 k 的数的数量. 析:数位DP,dp[i][j][k] 由于 k 最多是10,所以考虑是用状态压缩,表示 前 i 位,长度为 j,状态为 k的数量 ...
- hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)
#define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the entire ...
- HDU 4352 XHXJ's LIS HDU(数位DP)
HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...
- 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&状态压缩)
题目链接:[kuangbin带你飞]专题十五 数位DP B - XHXJ's LIS 题意 给定区间.求出有多少个数满足最长上升子序列(将数看作字符串)的长度为k. 思路 一个数的上升子序列最大长度为 ...
- hdu 4352 "XHXJ's LIS"(数位DP+状压DP+LIS)
传送门 参考博文: [1]:http://www.voidcn.com/article/p-ehojgauy-ot.html 题解: 将数字num字符串化: 求[L,R]区间最长上升子序列长度为 K ...
- HDU.4352.XHXJ's LIS(数位DP 状压 LIS)
题目链接 \(Description\) 求\([l,r]\)中有多少个数,满足把这个数的每一位从高位到低位写下来,其LIS长度为\(k\). \(Solution\) 数位DP. 至于怎么求LIS, ...
- $HDU$ 4352 ${XHXJ}'s LIS$ 数位$dp$
正解:数位$dp$+状压$dp$ 解题报告: 传送门! 题意大概就是港,给定$[l,r]$,求区间内满足$LIS$长度为$k$的数的数量,其中$LIS$的定义并不要求连续$QwQ$ 思路还算有新意辣$ ...
随机推荐
- Linux+Redis实战教程_day02_2、redis简述及安装与启动
2. redis简述及安装 关系型数据库(SQL): Mysql,oracle 特点:数据和数据之间,表和字段之间,表和表之间是存在关系的 例如:部门表 001部门, 员工表 001 用户表,用户 ...
- mysql asyn 实战
创建configuration时,发现URLParser找不到,于是只能使用配置文件来,当然使用配置文件比使用URL初始化还要直观些 def configurationWithPassword = n ...
- CSS属性中display="none“与visibility="hidden"的不同
display="none",元素会从页面移除,不在页面占用位置,当某个元素设置为display="none"时,这个元素后面的元素会移动上来 visibili ...
- linux-指定特殊域去重
测试数据: 2017-10-24 14:14:11:1123 [ INFO] order_type=add,order_id=9152017-10-24 14:14:11:1123 [ INFO] o ...
- iOS开发--关闭ARC
对整个项目关闭ARC project -> Build settings -> Apple LLVM complier 3.0 - Language -> objective-C A ...
- Unity弹出MessageBox
[DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = Char ...
- UML类图的几种关系总结【转】
在UML类图中,常见的有以下几种关系: 泛化(Generalization), 实现(Realization),关联(Association),聚合(Aggregation),组合(Composit ...
- 【Linux】 crontab 实现每秒执行
linux crontab 命令,最小的执行时间是一分钟, 如果要在小于一分钟执行.就要换个方法来实现 1 crontab 的延时: 原理:通过延时方法 sleep N 来实现每N秒执行. cr ...
- artdialog5 bug
1.使用artdialog5时,使用两个输入框传值,一直无法取到值,使用简单的ID无法取到值,如id=branch..改为id=branch_str_dialog就可以了,问题是解决了,可是没有找到原 ...
- Android 本地搭建Tomcat服务器供真机测试
准备工具:tomcat 环境:win7 + JDK1.8 + tomcat 9.0.13(64bit) 准备工具:tomcat 1.tomcat官网下载 https://tomcat. ...