当时Astar复赛的时候只做出1题,赛后补题(很长时间后才补,懒真是要命),发现这是第二简单的

分析:

这个题,可以每次二分区间的最小异或和

进行check的时候用dp进行判断,dp[i][j]代表前i个元素分成j个区间,j是最后一个区间的最后一个元素

如果dp[i][j]为真,表明每个区间长度大于L,异或和大于mid

否则为假

返回dp[n][m]就好

复杂度度 O(30^2*nm)

吐槽:和异或相关的题总是和字典树贪心有关,又是一道,铭记铭记

  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. using namespace std;
  5. const int N = 1e4+;
  6. typedef long long LL;
  7. int n,m,l,T,cas,tot;
  8. int a[N];
  9. struct Node{
  10. int sum,nex[];
  11. }p[N**];
  12. int newnode(){
  13. ++tot;
  14. p[tot].sum=;p[tot].nex[]=p[tot].nex[]=-;
  15. return tot;
  16. }
  17. int root[];
  18. void add(int pos,int x){
  19. int now=root[pos],cur;
  20. ++p[now].sum;
  21. for(int i=;i>=;--i){
  22. if(x&(<<i))cur=;
  23. else cur=;
  24. if(p[now].nex[cur]==-)
  25. p[now].nex[cur]=newnode();
  26. now=p[now].nex[cur];
  27. ++p[now].sum;
  28. }
  29. }
  30. void del(int pos,int x){
  31. int now=root[pos],cur;
  32. --p[now].sum;
  33. for(int i=;i>=;--i){
  34. if(x&(<<i))cur=;
  35. else cur=;
  36. now=p[now].nex[cur];
  37. --p[now].sum;
  38. }
  39. }
  40. int query(int pos,int x){
  41. int now=root[pos],ret=,cur;
  42. if(p[now].sum==)return ;
  43. for(int i=;i>=;--i){
  44. if(x&(<<i))cur=;
  45. else cur=;
  46. if(p[now].nex[cur^]!=-&&p[p[now].nex[cur^]].sum!=){
  47. ret+=(<<i);
  48. now=p[now].nex[cur^];
  49. }
  50. else now=p[now].nex[cur];
  51. }
  52. return ret;
  53. }
  54. bool dp[N][];
  55. bool check(int mid){
  56. tot=;
  57. for(int i=;i<m;++i)
  58. root[i]=newnode();
  59. for(int i=;i<=n;++i)
  60. for(int j=;j<=m;++j)dp[i][j]=false;
  61. dp[][]=true;add(,);
  62. for(int i=;i<=n;++i){
  63. if(i-l->=){
  64. for(int j=;j<=m;++j)
  65. if(dp[i-l-][j])del(j,a[i-l-]);
  66. }
  67. for(int j=;j<=m;++j){
  68. int tmp=query(j-,a[i]);
  69. if(tmp>=mid)add(j,a[i]),dp[i][j]=true;
  70. }
  71. }
  72.  
  73. return dp[n][m];
  74. }
  75. int main(){
  76. scanf("%d",&T);
  77. while(T--){
  78. scanf("%d%d%d",&n,&m,&l);
  79. for(int i=;i<=n;++i)
  80. scanf("%d",&a[i]),a[i]^=a[i-];
  81. int l=,r=1e9+,ret;
  82. while(l<=r){
  83. int mid=(l+r)>>;
  84. if(check(mid))l=mid+,ret=mid;
  85. else r=mid-;
  86. }
  87. printf("Case #%d:\n%d\n",++cas,ret);
  88. }
  89. return ;
  90. }

HDU5715 XOR 游戏 二分+字典树+dp的更多相关文章

  1. HDU 5715 XOR 游戏 二分+字典树

    XOR 游戏 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5715 Description 众所周知,度度熊喜欢XOR运算(XOR百科). 今天,它 ...

  2. Manthan, Codefest 16 C. Spy Syndrome 2 字典树 + dp

    C. Spy Syndrome 2 题目连接: http://www.codeforces.com/contest/633/problem/C Description After observing ...

  3. UVALive 3942 Remember the Word 字典树+dp

    /** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...

  4. Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)

    E. Ann and Half-Palindrome time limit per test 1.5 seconds memory limit per test 512 megabytes input ...

  5. HDU4825 Xor Sum(字典树解决最大异或问题)

    Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整 ...

  6. LA 3942 - Remember the Word (字典树 + dp)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. CF456D A Lot of Games (字典树+DP)

    D - A Lot of Games CF#260 Div2 D题 CF#260 Div1 B题 Codeforces Round #260 CF455B D. A Lot of Games time ...

  8. HDU--5269 ZYB loves Xor I (字典树)

    题目电波: HDU--5269 ZYB loves Xor I 首先我们先解决 ai xor aj 每个数转化为二进制  我们用字典树统计 每个节点 0 和 1 的出现的个数 #include< ...

  9. BZOJ 4260 Codechef REBXOR (区间异或和最值) (01字典树+DP)

    <题目链接> 题目大意:给定一个序列,现在求出两段不相交的区间异或和的最大值. 解题分析: 区间异或问题首先想到01字典树.利用前缀.后缀建树,并且利用异或的性质,相同的两个数异或变成0, ...

随机推荐

  1. 【转】Windows平台SSH登录Linux并使用图形化界面

    备注:经验证本文提供的方法可行且比使用VNC简洁一些.略有修改.   [日期:2011-09-06] 来源:Linux社区  作者:tianhuadihuo   http://www.linuxidc ...

  2. Spark Mllib逻辑回归算法分析

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3816289.html 本文以spark 1.0.0版本MLlib算法为准进行分析 一.代码结构 逻辑回归 ...

  3. Intellij 导入play framework 项目

    新建一个项目 play new helloworld IshallbeThatIshallbe:~ iamthat$ mkdir temp IshallbeThatIshallbe:~ iamthat ...

  4. BZOJ 3198 SDOI2013 spring

    为什么SDOI省选一年考两次容斥原理? 我们很容易发现>=k个相等时很好计算的 但是我们要求恰好k个,那么我们容斥即可 至于计算>=k个相等,首先我们枚举相等位置,对每个串对应位置做一遍h ...

  5. React测试Mixin

    1.test.jsx var randomNumberMixin = require("./randomNumberMixin.jsx"); describe("test ...

  6. HTTP长连接实现“服务器推”的技术

    HTTP长连接实现“服务器推”的技术快速入门及演示示例 在我的印象里HTTP是一种“无状态的协议”,也就是不知道以前请求的历史,无法保留上一次请求的结果.Cookie的诞生,弥补了这个不足,浏览器可以 ...

  7. Java对象的序列化(Object Serialization)

    先定义两个简单的类: package comm; import java.io.Serializable; import java.util.Date; import java.util.Gregor ...

  8. 车牌识别LPR(一)-- 研究背景

    在年尾用了几天的时间将2014年的所有工作都总结了一遍,将之前的文档综合了下. 以下是LPR系统,车牌识别的一些总结资料. 第一篇:LPR研究背景 汽车的出现改变了以往出行徒步和以马代步的时代,极大地 ...

  9. ubuntu set host name

    http://wiki.joyent.com/wiki/display/jpc2/Setting+the+Host+Name+on+a+Linux+VM Set the host name in th ...

  10. 【Latex】如何在Latex中插入伪代码 —— clrscode3e

    1. 简介clrscode3e是<算法导论(第三版)>使用的伪代码的宏包,clrs其实表示的是Cormen.Leiserson.Rivest和Stein.它有个更老的版本clrscode, ...