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 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
  1. /*
  2. hdu 4352 数位dp + 状态压缩
  3.  
  4. problem:
  5. 求[L,R]之间有多少个数,把它们看成字符串,其LIS == k.
  6.  
  7. solve:
  8. 很明显的数位dp,考虑怎么保存状态. k <= 10,所以可以用二进制来模拟lis的操作保存状态.
  9. dp[i][j][k]表示 到第i位,lis状态为j,所求为k的情况.
  10.  
  11. hhh-2016-08-26 20:06:21
  12. */
  13. #pragma comment(linker,"/STACK:124000000,124000000")
  14. #include <algorithm>
  15. #include <iostream>
  16. #include <cstdlib>
  17. #include <cstdio>
  18. #include <cstring>
  19. #include <vector>
  20. #include <math.h>
  21. #include <queue>
  22. #include <map>
  23. #define lson i<<1
  24. #define rson i<<1|1
  25. #define ll long long
  26. #define clr(a,b) memset(a,b,sizeof(a))
  27. #define scanfi(a) scanf("%d",&a)
  28. #define scanfl(a) scanf("%I64d",&a)
  29. #define key_val ch[ch[root][1]][0]
  30. #define inf 0x3f3f3f3f
  31. using namespace std;
  32. const ll mod = 1e9+7;
  33. const int maxn = 1004;
  34.  
  35. ll a,b;
  36. int k;
  37. ll dp[70][1<<10][11];
  38. int t[70],tot;
  39.  
  40. int make_in(int x,int z)
  41. {
  42. for(int i = x;i <= 10;i++)
  43. {
  44. if( (1 << i) & z)
  45. {
  46. z ^= (1 << i);
  47. z |= (1 << x);
  48. return z;
  49. }
  50. }
  51. return (z |= (1<<x));
  52. }
  53.  
  54. int make_sum(int x)
  55. {
  56. int num = 0;
  57. for(int i = 0;i <= 9;i++)
  58. {
  59. if((1 << i) & x)
  60. num ++;
  61. }
  62. return num;
  63. }
  64.  
  65. ll dfs(ll len,int state,bool flag,bool first)
  66. {
  67. ll ans = 0;
  68. if(len < 0)
  69. return make_sum(state) == k;
  70.  
  71. int n = flag ? t[len]:9;
  72. if(!flag && dp[len][state][k] != -1)
  73. return dp[len][state][k];
  74. for(int i = 0;i <= n;i++)
  75. {
  76. ans += dfs(len-1,(first&&!i)? 0:make_in(i,state),flag && i == n,first && i == 0);
  77. }
  78.  
  79. if(!flag)
  80. dp[len][state][k] = ans;
  81. return ans;
  82. }
  83.  
  84. ll cal(ll cur)
  85. {
  86. tot = 0;
  87. while(cur)
  88. {
  89. t[tot ++] = cur%10;
  90. cur /= 10;
  91. }
  92. return dfs(tot-1,0,1,1);
  93. }
  94.  
  95. int main()
  96. {
  97. // freopen("in.txt","r",stdin);
  98. int T,cas= 1;
  99. scanfi(T);
  100. memset(dp,-1,sizeof(dp));
  101. while(T--)
  102. {
  103. scanfl(a),scanfl(b),scanfi(k);
  104. // cout << cal(a-1) << " " << cal(b) <<endl;
  105. printf("Case #%d: %I64d\n",cas++,cal(b) - cal(a-1));
  106. }
  107. return 0;
  108. }

  

hdu 4352 数位dp + 状态压缩的更多相关文章

  1. hdu_4352_XHXJ's LIS(数位DP+状态压缩)

    题目连接:hdu_4352_XHXJ's LIS 题意:这题花大篇篇幅来介绍电子科大的一个传奇学姐,最后几句话才是题意,这题意思就是给你一个LL范围内的区间,问你在这个区间内最长递增子序列长度恰为K的 ...

  2. 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 ...

  3. 【HDU 4352】 XHXJ's LIS (数位DP+状态压缩+LIS)

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

  4. hdu 4352 XHXJ's LIS (数位dp+状态压缩)

    Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully readin ...

  5. SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]

    题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...

  6. hdu4352 数位dp+状态压缩+一个tip

    按照nlogn求lis的方法,把lis的状态压缩了,每次新加一个数就把它右边第一个数的位置置为0,然后把这个数加进去 一个需要注意的地方,如果前面都是0,那么状态s中代表0的位置不可以是1,因为这种情 ...

  7. HDU 4352 数位dp

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

  8. hdu 4352 数位dp+nlogn的LIS

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

  9. [HDU 4842]--过河(dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4842 过河 Time Limit: 3000/1000 MS (Java/Others)    Mem ...

随机推荐

  1. C语言作业--数据类型

    一.PTA实验作业 题目1:7-7 发红包 1. 本题PTA提交列表 2. 设计思路 1定义整型变量hundred,fifty,twenty,ten,five,two,one分别存放不同金额的张数,n ...

  2. 使用Flask-SQLAlchemy管理数据库

    SQLAlchemy 是一个很强大的关系型数据库框架,处于数据库抽象层 ,支持多种数据库后台. 提供了高层 ORM,也提供了使用数据库原生 SQL 的低层功能. 安装Flask-SQLAlchemy ...

  3. Beta阶段敏捷冲刺报告-DAY5

    Beta阶段敏捷冲刺报告-DAY5 Scrum Meeting 敏捷开发日期 2017.11.6 会议时间 12:00 会议地点 软工所 参会人员 全体成员 会议内容 乱序问题的解决,异常输入提示 讨 ...

  4. 201621123068 Week03-面向对象入门

    1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系.步骤如下: 1.1 写出你 ...

  5. 201621123057 《Java程序设计》第4周学习总结

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 答: (普通方法 / 构造函数)重载. static . final.继承与多态.extends.object类.abstrac ...

  6. Scrum 冲刺 第三日

    Scrum 冲刺 第三日 目录 要求 项目链接 燃尽图 问题 今日任务 明日计划 成员贡献量 要求 各个成员今日完成的任务(如果完成的任务为开发或测试任务,需给出对应的Github代码签入记录截图:如 ...

  7. SQL之Left Join 关联条件的探讨

    在测试工作中,有时需要测试数据库数据经过sql计算后的结果是否满足某一功能查询得到的返回值. 针对某些需要功能需要联查多张表,此时 关联 的作用就异常重要了,而针对多表关联,其中 关联条件的重要性不言 ...

  8. Win10安装Ubuntu14.04.5双系统(显示器为DP接口)

    系统安装主要参考了这篇博文Win10+Ubuntu17.04双系统安装,不再重复. 重点说说DP接口的事,如果主机有VGA接口的话可以到此为止了,如果只有DP接口的话可以参考以下内容. 一.Ubunt ...

  9. mosquitto安装和测试

    一.安装 1.windows安装 安装完毕,更新安装目录的dll文件 2.linux安装 编译保存用户数据到数据库的插件 安装 3.启动 mosquitto mosquitto mosquitto_p ...

  10. Django Form组件 学生管理系统

    from django.db import models # Create your models here. class Classes(models.Model): title=models.Ch ...