HDU4352XHXJ's LIS(dp状态压缩)

XHXJ‘s LIS

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 809    Accepted Submission(s): 308

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

参考资料:http://download.csdn.net/detail/fljssj/7731401

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int k;
int q[20];
__int64 dp[20][1<<10][11];//第几位,二进制压缩的状态,递增子序列长度
int gety(int y,int i)//得到新的状态
{
    for(int x=i;x<=9;x++)
    {
        if(y&(1<<x))
            return (y^(1<<x))|(1<<i);
    }
    return y|(1<<i);
}
int pd(int y)
{
    int s=0;
    while(y)
    {
        if(y&1)
        s++;
        y>>=1;
    }
    return s;
}
__int64 dfs(int len,int y,int z,int flag)
{
    if(len<0)return pd(y)==k;
    if(!flag&&dp[len][y][k]!=-1)
        return dp[len][y][k];
    int n = flag ? q[len] : 9;
    __int64 ans=0;
    for(int i=0;i<=n;i++)
    {
        ans+=dfs(len-1,(z&&(i==0)) ? 0 : gety(y,i),z&&(i==0),flag&&(i==n));
    }
    if(!flag)
        dp[len][y][k]=ans;
    return ans;
}
__int64 work(__int64 a)
{
    int len=0;
    while(a)
    {
        q[len++]=a%10;
        a/=10;
    }
    return dfs(len-1,0,1,1);
}
int main()
{
    int t,tt=1;
    scanf("%d",&t);
    memset(dp,-1,sizeof dp);
    while(t--)
    {
        __int64 a,b;
        scanf("%I64d%I64d%d",&a,&b,&k);
        printf("Case #%d: %I64d\n",tt++,work(b)-work(a-1));
    }
    return 0;
}

HDU4352XHXJ's LIS(dp状态压缩)

时间: 2024-10-25 20:05:23

HDU4352XHXJ's LIS(dp状态压缩)的相关文章

【HDU 4352】 XHXJ&#39;s LIS (数位DP+状态压缩+LIS)

XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2422    Accepted Submission(s): 990 Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then careful

[数位dp+状态压缩] hdu 4352 XHXJ&#39;s LIS

题意: 给x.y.k,在[x,y] 范围内最长上升子序列长度是k的数有几个 思路: 模仿 LIS nlogn的想法,这里就只有10个数,进行状压 然后直接搜就好了不用二分 然后按位dp下去就ok了! 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #include"al

hdu 4352 数位dp + 状态压缩

XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2265    Accepted Submission(s): 927 Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then careful

dp状态压缩

dp状态压缩 动态规划本来就很抽象,状态的设定和状态的转移都不好把握,而状态压缩的动态规划解决的就是那种状态很多,不容易用一般的方法表示的动态规划问题,这个就更加的难于把握了.难点在于以下几个方面:状态怎么压缩?压缩后怎么表示?怎么转移?是否具有最优子结构?是否满足后效性?涉及到一些位运算的操作,虽然比较抽象,但本质还是动态规划.找准动态规划几个方面的问题,深刻理解动态规划的原理,开动脑筋思考问题.这才是掌握动态规划的关键. 动态规划最关键的要处理的问题就是位运算的操作,容易出错,状态的设计也直

HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由于得到每张卡片的状态不知道,所以用状态压缩,dp[i] 表示这个状态时,要全部收齐卡片的期望. 由于有可能是什么也没有,所以我们要特殊判断一下.然后就和剩下的就简单了. 另一个方法就是状态压缩+容斥,同样每个状态表示收集的状态,由于每张卡都是独立,所以,每个卡片的期望就是1.0/p,然后要做的就是要去重,既然

uva 11367 dijkstra+dp状态压缩

题意:给出n个地点 和 每个地点的油价 ,有 m 条边 , 并给出每条边长度 .1单位汽油可以走1千米  , 油箱的容量为 c , 在初始点 s 时 , 油箱中的油为 0 , 求s 到 t 的最小花费 . 解法: 定义 状态 d[i][j] 表示到达 地点 i 且油箱中有 j 单位油时的最小 花费. 对于状态的转移时 , 有两种方法: 1.把每个点的所有状态都求出 2.不把每个点的状态都求出 , 而是一单位一单位的加油. 对于第一种方法 , 会超时 , 因为每个点的状态太多 , 但是能用的状态就

Uva 10817 Headmaster&#39;s Headache (DP+ 状态压缩)

Problem D: Headmaster's Headache Time limit: 2 seconds The headmaster of Spring Field School is considering employing some new teachers for certain subjects. There are a number of teachers applying for the posts. Each teacher is able to teach one or

(hiho1048)POJ2411Mondriaan&#39;s Dream(DP+状态压缩 or 轮廓DP)

问题: Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangle

vijos - P1286座位安排 (DP状态压缩 + 组合数 + python)

P1286座位安排 Accepted 标签:[显示标签] 背景 快要期中考试了!老师需要hzy帮他排考试的座位... 描述 考场里的座位恰好有n行m列,并且恰好有n*m位考生在这个考场里面考试,也就是说,所有的座位上都有考生.hzy根据学校记载,有k位考生可能作弊,因此hzy不能让他们之中的任何两个人做在相邻的座位上!所谓相邻的座位,即在同一行相邻列或者在同一列的相邻行的座位.hzy准备这样安排座位,首先随机选择一种方案,如果这种方案是合法的,就用这种方案,否则重新选择.你的任务是计算,他得到一