XHXJ's LIS

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3081    Accepted Submission(s): 1291

Problem Description
#define xhxj (Xin Hang senior sister(学姐)) 
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。
 
Input
First a integer T(T<=10000),then T lines follow, every line has three positive integer L,R,K.(
0<L<=R<263-1 and 1<=K<=10).
 
Output
For each query, print "Case #t: ans" in a line, in which t is the number of the test case starting from 1 and ans is the answer.
 
Sample Input
1
123 321 2
 
Sample Output
Case #1: 139
 
Author
peterae86@UESTC03
 
Source
 

题意:

求[L,R]区间中有多少这样的数:把他看成字符串时他的LIS长度是k

代码:

//数位dp+LIS的那个nlogn方法。用sta(二进制压缩)记录LIS中涉及到了那些数。还要注意前导0的处理。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=;
int bit[],k;
ll dp[][<<][];
int yes(int sta)
{
int cnt=;
while(sta){
cnt+=sta&;
sta>>=;
}
return cnt==k;
}
int make(int x,int sta)
{
int i;
for(i=;i<=;i++)
if(sta&(<<i)&&i>=x) break;
if(i<=){
sta^=(<<i);
sta|=(<<x);
}else sta|=(<<x);
return sta;
}
ll dfs(int pos,int sta,bool limt,bool zero)
{
if(pos==) return yes(sta);
if(!limt&&dp[pos][sta][k]!=-)
return dp[pos][sta][k];
ll ans=;
int maxb=(limt?bit[pos]:);
for(int i=;i<=maxb;i++){
int ssta=make(i,sta);
ans+=dfs(pos-,(zero&&i==)?:ssta,limt&&(i==maxb),zero&&i==);
}
if(!limt)
dp[pos][sta][k]=ans;
return ans;
}
ll solve(ll n)
{
int nu=;
while(n){
bit[++nu]=n%;
n/=;
}
return dfs(nu,,,);
}
int main()
{
int t;
ll L,R;
memset(dp,-,sizeof(dp));
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
scanf("%lld%lld%d",&L,&R,&k);
printf("Case #%d: %lld\n",cas,solve(R)-solve(L-));
}
return ;
}

HDU 4352 数位dp的更多相关文章

  1. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. hdu 4352 数位dp+nlogn的LIS

    题意:求区间L到R之间的数A满足A的的数位的最长递增序列的长度为K的数的个数. 链接:点我 该题的关键是记录LIS的状态,学习过nlogn解法的同学都知道,我们每次加入的元素要和前面的比对替换,这里就 ...

  3. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

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

    HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...

  5. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  6. hdu:2089 ( 数位dp入门+模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...

  7. hdu 3709 数位dp

    数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...

  8. HDU 2089 数位dp入门

    开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...

  9. HDU 2089 数位dp/字符串处理 两种方法

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. Digital Roots:高精度

    C - Digital Roots Description The digital root of a positive integer is found by summing the digits ...

  2. 《Cocos2d-x游戏开发实战精解》学习笔记1--在Cocos2d中显示图像

    Cocos2d-x中的图像是通过精灵类来显示的.在Cocos2d-x中游戏中的每一个角色.怪物.道具都可以理解成是一个精灵,游戏背景作为一种特殊的单位将其理解成是一个精灵也没有什么不妥.在源文件本章目 ...

  3. 在GPT格式的硬盘上,使用EFI启动的方式,安装Win7 64位系统

    Win7 sp1 原装系统,用UltraISO(软碟通) 把U 盘制成Win7 安装的启动U盘 将bootmgfw.efi和shell.efi 加到已制好启动U盘的根目录,并在efi/boot/路径下 ...

  4. 在香港网站使用工商银行的MasterCard,工商银行所犯的低级的错误,金融安全何在

  5. Hyper-V虚拟机联网设置

    转自:http://www.3lian.com/edu/2012/12-22/50492.html Windows 8中内置的Hyper-V管理器可以说给许多人带来了惊喜!在Hyper-V管理器强大的 ...

  6. python爬虫调用搜索引擎及图片爬取实战

    实战三-向搜索引擎提交搜索请求 关键点:利用搜索引擎提供的接口 百度的接口:wd="要搜索的内容" 360的接口:q="要搜索的内容" 所以我们只要把我们提交给 ...

  7. 寒假作业2——Pintia小作业及编程题

    编程题(电梯)       Click to Github       听华一大大说可以用回溯算法,熟练运用搜索引擎的我就百度了一下,琢磨了很多天以为自己会了,真的看到题目还是一脸懵逼(#`-_ゝ-) ...

  8. Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp

    题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...

  9. float精度丢失的问题

    在做IPTV的时候,遇到以下这个问题: 现有一个float型数据,以下代码打印输出: float n = 40272.48f; System.out.println(new Double(n * 10 ...

  10. web_config配置

    <configuration>    <system.web>      <compilation debug="true" targetFramew ...