hdu 4352 - XHXJ's LIS (数位dp)多校联合

原创 2015年07月06日 22:16:36


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。


First a integer T(T<=10000),then T lines follow, every line has three positive integer L,R,K.(


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

123 321 2

Sample Output

Case #1: 139

题意:先定义一个数的power value,把这个数看成一个字符串,他的最长上升子序列的长度就是他的power value,求某个区间内power value等于k的数的个数。

using namespace std;
typedef long long LL;
const int maxn=70;
int K;
int dig[maxn];
LL dp[maxn][1024][11];
int getnum(int S)
    int sum=0;
    for(int i=0;i<10;i++)
    return sum;
int getnew(int S,int x)
    for(int i=x;i<10;i++)
        if(S&(1<<i))return (S^(1<<i))|(1<<x);
    return S|(1<<x);
LL dfs(int cur,int e,int z,int S)
    if(cur<0)return getnum(S)==K;
        return dp[cur][S][K];
    int end=e?dig[cur]:9;
    LL ans=0;
    for(int i=0;i<=end;i++)
        else ans+=dfs(cur-1,e&&i==end,0,getnew(S,i));
    return ans;
LL solve(LL x)
    int len=0;

    return dfs(len-1,1,1,0);
int main()
    int T,cas=1;
        printf("Case #%d: %I64d\n",cas++,solve(R)-solve(L-1));
    return 0;

XHXJ's LIS HDU4352(数位DP)

为在[L, R]区间中, 组成数字严格上升并且长度为K的个数 主要是状态的变化, 这里用了状态压缩来压缩一个10位数, 对于1356  长度不变的情况下如果要插入4,更具O(nlgn) 的LIS...
  • u013008291
  • u013008291
  • 2015年06月18日 23:17
  • 617


题目分析 这道题前面说了一堆废话,不过这道题还是很有水准的,不愧是多校的题目。这道题就是让你求给定2个数字,让你求这2个数字之间的有多少个数字满足数字的每一位上的数组成的最长递增子序列为K。看这道...
  • chen_ze_hua
  • chen_ze_hua
  • 2016年07月22日 20:32
  • 188

HDU 4352 XHXJ's LIS 数位dp

题目链接:点击打开链接 题意: 一个数自身的最长子序列=每一位都是一个数字然后求的LIS 问区间内有多少个数 自身的最长子序列==k 思路: 因为自身的最长子序列至多=10,且由0~9组成,...
  • qq574857122
  • qq574857122
  • 2015年04月01日 21:05
  • 813

hdu 4352 XHXJ's LIS(数位DP)

XHXJ's LIS Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S...
  • yjf3151731373
  • yjf3151731373
  • 2016年10月25日 10:16
  • 104

HDU 4352 XHXJ's LIS(状态压缩+数位dp)

题目链接 求区间里面的数,满足数位上的数是严格的长度为k的上升子序列的个数上升子序列使用nlogn的计算方式,因为是严格的上升子序列,所以只会有0-9,10个数字。在某一个上升的子序列中,每个数字只...
  • u013167299
  • u013167299
  • 2016年09月22日 13:45
  • 143

hdu 4352 XHXJ's LIS(数位dp)

题目链接 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...
  • fouzhe
  • fouzhe
  • 2016年09月11日 11:20
  • 120

【HDU】4352 XHXJ's LIS 数位DP

传送门:【HDU】4352 XHXJ's LIS 题目分析:dp[
  • u013368721
  • u013368721
  • 2014年11月18日 19:08
  • 963

HDU 4352 XHXJ's LIS(数位DP)

【题意】 问区间[L, R]里面满足 LIS == k的数字个数。 【解题方法】 LIS运用动态规划可以在nlogn的时间复杂度解决,此略。 因为最多只有0-9十个数字,因此可以预...
  • just_sort
  • just_sort
  • 2016年08月10日 15:23
  • 339

hdu 4352 XHXJ's LIS 状压数位dp

求a - b 的按每位值来最长lis长度为k的个数 当求lis时 每加入一个数看此时的lis中有没有数大于等于它且前一个数小于它,有的话将这个位置替换成这个数,没有的话把它填入到末尾 lis+1 ...
  • acblacktea
  • acblacktea
  • 2016年09月01日 20:49
  • 150

【hdu】4352 XHXJ's LIS【状压+数位dp】

题意:题目这么长,其实就是找出区间内如果把数字看成一个阿拉伯数字的集合的话,这个集合中最长严格上升子序列的长度为k的个数 题解:主要是如何储存之前的状态比较难想,考虑到有0-9十个数字和nlogn的...
  • a709743744
  • a709743744
  • 2016年07月12日 10:06
  • 155
您举报文章:hdu 4352 - XHXJ's LIS (数位dp)多校联合