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$ 思路还算有新意辣$ ...
随机推荐
- Spring父容器与子容器
在使用spring+springMVC的web工程中,我们一般会在web.xml中做如下配置: <context-param> <param-name>contextConfi ...
- 一致性Hash算法原理及C#代码实现
一.一致性Hash算法原理 基本概念 一致性哈希将整个哈希值空间组织成一个虚拟的圆环,如假设某哈希函数H的值空间为0-2^32-1(即哈希值是一个32位无符号整形),整个哈希空间环如下: 整个空间按顺 ...
- 产品半夜发现bug让程序员加班,程序员应如何回应?
群友半夜2点被产品叫起来改东西,然后他打车去公司加班,群友愤慨,特为此创作一个小段子 产品:XXX出bug了你赶紧看看 修复一下 开发:我宿舍没电脑 没网络啊 产品:你看看周围有没有网吧远程一下 或者 ...
- mysql 外键约束示例
-- 创建测试主表. ID 是主键.CREATE TABLE test_main ( id INT, value VARCHAR(10), PRIMARY KEY(id)); -- ...
- ARM9通过NFS挂载根文件系统
当开发板启动以后可以通过在超级终端发送命令来配置NFS. 首先得给开发板一个IP地址,用下面的命令配置即可: #ifconfig 192.168.0.10 经过上面的配置以后在各自的终端中应该都能PI ...
- MyEclipse中自定义maven命令(添加maven 命令)
关于常用的Maven命令 mvn archetype:create :创建 Maven 项目 mvn compile :编译源代码 mvn test-compile :编译测试代码 mvn test ...
- JS - 查找同辈中的对象
今天在使用parent().find(".a:first")的时候,发现查找结果非正常按照顺序来的.有点递归的感觉,从底层往上. 因为需要的是同级的对象,所以去查了一下jquery ...
- sqlserver添加查询 表、字段注释(转)
环境:xp sp3,sql server2008 .sqlserver用语句给表注释 EXECUTE sp_addextendedproperty N'MS_Description', N'表注释', ...
- IOS设计模式第三篇之外观设计模式
外观设计模式: 这个外观设计模式提供了一个单独的接口给复杂的子系统.而不是暴露用户的一组类和API,你仅仅暴露一个简单的同一的API. 下面的图片解释这个概念: API的用户根本不知道后面系统的复杂性 ...
- WP8.1学习系列(第二十章)——添加控件和处理事件
先决条件 添加控件 设置控件的名称 设置控件属性 创建事件处理程序 新控件 总结 相关主题 通过使用如按钮.文本框和组合框等控件,你可以创建应用的 UI. 下面将显示如何将控件添加到应用.处理控件时, ...