HDU5715 XOR 游戏 二分+字典树+dp
当时Astar复赛的时候只做出1题,赛后补题(很长时间后才补,懒真是要命),发现这是第二简单的
分析:
这个题,可以每次二分区间的最小异或和
进行check的时候用dp进行判断,dp[i][j]代表前i个元素分成j个区间,j是最后一个区间的最后一个元素
如果dp[i][j]为真,表明每个区间长度大于L,异或和大于mid
否则为假
返回dp[n][m]就好
复杂度度 O(30^2*nm)
吐槽:和异或相关的题总是和字典树贪心有关,又是一道,铭记铭记
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N = 1e4+;
typedef long long LL;
int n,m,l,T,cas,tot;
int a[N];
struct Node{
int sum,nex[];
}p[N**];
int newnode(){
++tot;
p[tot].sum=;p[tot].nex[]=p[tot].nex[]=-;
return tot;
}
int root[];
void add(int pos,int x){
int now=root[pos],cur;
++p[now].sum;
for(int i=;i>=;--i){
if(x&(<<i))cur=;
else cur=;
if(p[now].nex[cur]==-)
p[now].nex[cur]=newnode();
now=p[now].nex[cur];
++p[now].sum;
}
}
void del(int pos,int x){
int now=root[pos],cur;
--p[now].sum;
for(int i=;i>=;--i){
if(x&(<<i))cur=;
else cur=;
now=p[now].nex[cur];
--p[now].sum;
}
}
int query(int pos,int x){
int now=root[pos],ret=,cur;
if(p[now].sum==)return ;
for(int i=;i>=;--i){
if(x&(<<i))cur=;
else cur=;
if(p[now].nex[cur^]!=-&&p[p[now].nex[cur^]].sum!=){
ret+=(<<i);
now=p[now].nex[cur^];
}
else now=p[now].nex[cur];
}
return ret;
}
bool dp[N][];
bool check(int mid){
tot=;
for(int i=;i<m;++i)
root[i]=newnode();
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)dp[i][j]=false;
dp[][]=true;add(,);
for(int i=;i<=n;++i){
if(i-l->=){
for(int j=;j<=m;++j)
if(dp[i-l-][j])del(j,a[i-l-]);
}
for(int j=;j<=m;++j){
int tmp=query(j-,a[i]);
if(tmp>=mid)add(j,a[i]),dp[i][j]=true;
}
} return dp[n][m];
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&l);
for(int i=;i<=n;++i)
scanf("%d",&a[i]),a[i]^=a[i-];
int l=,r=1e9+,ret;
while(l<=r){
int mid=(l+r)>>;
if(check(mid))l=mid+,ret=mid;
else r=mid-;
}
printf("Case #%d:\n%d\n",++cas,ret);
}
return ;
}
HDU5715 XOR 游戏 二分+字典树+dp的更多相关文章
- HDU 5715 XOR 游戏 二分+字典树
XOR 游戏 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5715 Description 众所周知,度度熊喜欢XOR运算(XOR百科). 今天,它 ...
- Manthan, Codefest 16 C. Spy Syndrome 2 字典树 + dp
C. Spy Syndrome 2 题目连接: http://www.codeforces.com/contest/633/problem/C Description After observing ...
- UVALive 3942 Remember the Word 字典树+dp
/** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...
- 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 ...
- HDU4825 Xor Sum(字典树解决最大异或问题)
Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整 ...
- LA 3942 - Remember the Word (字典树 + dp)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 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 ...
- HDU--5269 ZYB loves Xor I (字典树)
题目电波: HDU--5269 ZYB loves Xor I 首先我们先解决 ai xor aj 每个数转化为二进制 我们用字典树统计 每个节点 0 和 1 的出现的个数 #include< ...
- BZOJ 4260 Codechef REBXOR (区间异或和最值) (01字典树+DP)
<题目链接> 题目大意:给定一个序列,现在求出两段不相交的区间异或和的最大值. 解题分析: 区间异或问题首先想到01字典树.利用前缀.后缀建树,并且利用异或的性质,相同的两个数异或变成0, ...
随机推荐
- jQuery从主页面存取控制 iframe 中的元素,参数及方法
从主页面上获取iframe下的某个对象,或使用iframe下的方法,或是获取iframe下某个doc元素,要求兼容各类浏览器,不仅仅ie; $(function() { $('#abgne_ifram ...
- lintcode:First Missing Positive 丢失的第一个正整数
题目 丢失的第一个正整数 给出一个无序的整数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许时 ...
- 360云盘、百度云、微云……为什么不出 OS X(Mac 端)应用呢?(用户少,开发成本高)(百度网盘Mac版2016.10.18横空出世)
已经说的很好了,现有的云盘所谓的 OS X 版只有云同步功能,不过 115 是个例外,不过 115 的现状……不言自明.接下来说点和本题答案无关的,其实在官方客户端流氓 + 限速的大背景下 OS X ...
- Android:EditText 常用属性
属性 作用 android:hint="输入邮箱/用户名" 提示信息 android:inputType="textPassword" 设置文本的类型 andr ...
- jQuery好用插件
jQuery图片轮播插件(smallslider):http://fz.sjtu.edu.cn/zsw/js/smallslider/ jQuery消息通知(noty):http://www.360d ...
- 7、SpringMVC源码分析(2):分析HandlerAdapter.handle方法,了解handler方法的调用细节以及@ModelAttribute注解
从上一篇 SpringMVC源码分析(1) 中我们了解到在DispatcherServlet.doDispatch方法中会通过 mv = ha.handle(processedRequest, res ...
- Spring中的mappingResources和mappingDirectoryLocations
今天使用Spring+Hibernate进行事务管理,按照顺序也就是配置,DataSource,Sessionfactory,事务管理器以及拦截器. DateSource可以直接使用Hibernate ...
- C#使用sharppcap实现网络抓包
sharppcap dll的下载地址: http://sourceforge.net/directory/os:windows/?q=sharppcap 具体使用详细步骤: http://www.co ...
- HDU 4717 The Moving Points(三分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...
- Codeforces Round #239 (Div. 2)
做了三个题,先贴一下代码...终于涨分了 A. Line to Cashier 水题 #include <iostream> #include <cstdio> #includ ...