ZCC loves cards

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 2362 Accepted Submission(s): 590

Problem Description
ZCC loves playing cards. He has n magical cards and each has a number on it. He wants to choose k cards and place them around in any order to form a circle. He can choose any severalconsecutive cards the number of
which is m(1<=m<=k) to play a magic. The magic is simple that ZCC can get a number x=a1⊕a2...⊕am, which ai means the number on the ith card he chooses. He can play the magic infinite times, butonce he begin to play the magic, he can’t change anything
in the card circle including the order.


ZCC has a lucky number L. ZCC want to obtain the number L~R by using one card circle. And if he can get other numbers which aren’t in the range [L,R], it doesn’t matter. Help him to find the maximal R.
Input
The input contains several test cases.The first line in each case contains three integers n, k and L(k≤n≤20,1≤k≤6,1≤L≤100). The next line contains n numbers means the numbers on the n cards. The ith number a[i] satisfies 1≤a[i]≤100.

You can assume that all the test case generated randomly.
Output
For each test case, output the maximal number R. And if L can’t be obtained, output 0.
Sample Input
4 3 1
2 3 4 5
Sample Output
7
Hint
⊕ means xor
Author
镇海中学
Source

题意:给n个数。从中选出k个数,这k个数能够随意排列,一旦定了顺序就不能改变,在这个确定的顺序。选出m(m<=k)个数异或得到的值x,在这个顺序得到的全部x的值中找出一个最大值R,这些数中使得存在一个连续的范围L~R。

#include<stdio.h>
#include<string.h>
int n,k,L,ans[25];
int a[13],aa[13],R,flag[150];
int vist[10];
void find(int tk)
{
if(tk==k-1)
{
memset(flag,0,sizeof(flag));
for(int i=0;i<k-1;i++)
a[i+k]=a[i];
int maxa=0;
for(int i=0;i<k;i++)//枚举一个确定序列的连续片断的异或值
{
int x=a[i]; flag[x]=1; if(maxa<x)maxa=x;
for(int j=i+1;j-i+1<=k;j++)
{
x^=a[j]; flag[x]=1;if(maxa<x)maxa=x;
}
}
int r=0;
for(int i=L;i<=maxa;i++)//找出这个最大值R,使得这些数存在L~R范围的数都存在。
if(flag[i]==0)break;
else r=i;
if(r>R)R=r;
return ;
}
tk++;
for(int i=0;i<k;i++)
if(vist[i]==0)
{
a[tk]=aa[i]; vist[i]=1; find(tk); vist[i]=0;
}
}
bool panduan()//放宽条件(随意顺序)推断
{
memset(flag,0,sizeof(flag));
int maxa=0;
for(int i=1;i<(1<<k);i++)
{
int x=0;
for(int j=0;(1<<j)<=i;j++)
if((1<<j)&i)x^=aa[j];
flag[x]=1;
if(maxa<x)maxa=x;
}
int r=0;
for(int i=L;i<=maxa;i++)
if(flag[i]==0)break;
else r=i;
return r>R;
}
void CNM(int tk,int i)
{
if(tk==k-1)
{
if(panduan())
find(-1);
return ;
}
tk++;
for(int j=i+1;j<n;j++)
{
aa[tk]=ans[j]; CNM(tk,j);
}
}
int main()
{
while(scanf("%d%d%d",&n,&k,&L)>0)
{
R=0; memset(vist,0,sizeof(vist));
for(int i=0;i<n;i++)
scanf("%d",&ans[i]);
CNM(-1,-1);
printf("%d\n",R);
}
}

HDU4876ZCC loves cards(多校题)的更多相关文章

  1. 多校训练赛2 ZCC loves cards

    ZCC loves cards Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU 4876 ZCC loves cards(暴力剪枝)

    HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...

  3. hdu 4876 ZCC loves cards(暴力)

    题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...

  4. HDOJ 4876 ZCC loves cards

    枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝. 通过检測的暴力计算一遍 ZCC loves cards Time Limit: 4000/2000 MS (Ja ...

  5. HDU4876:ZCC loves cards

    Problem Description ZCC loves playing cards. He has n magical cards and each has a number on it. He ...

  6. 5805 NanoApe Loves Sequence(想法题)

    传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K ( ...

  7. hdu 5264 pog loves szh I 水题

    pog loves szh I Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  8. hdu6062RXD and logic gates多校题 构造

    听说标算的点数是2^(n+1)级别的,也不知道我是不是比标算优一点? (话说这种题一眼看过去怎么跟题答一样) 然而并不是题答,没法手玩,来考虑一下一般解法: 考虑一个规模较小的问题:最后一位一定是0 ...

  9. HDU 5273 Dylans loves numbers(水题)

    题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...

随机推荐

  1. oc 可变參数传递

    - (id)initWithFrame:(CGRect)frame delegate:(id<SGFocusImageFrameDelegate>)delegate focusImageI ...

  2. Java 23种设计模式详尽分析与实例解析之三--行为型模式

    Java设计模式 行为型模式 职责链模式 模式动机:职责链可以是一条直线.一个环或者一个树形结构.链上的每一个对象都是请求处理者,职责链模式可以将请求的处理组织成一条链,并使请求链传递,由链上的处理者 ...

  3. Qt控件精讲一:按钮

    原地址:http://blog.csdn.net/yuxikuo_1/article/details/17397109 Qt Creater提供6种Button控件.如图1. Button控件介绍 控 ...

  4. 南京三星面试准备3--数组&基础数据结构

    1.用递归颠倒一个栈. void PushToBottom(stack<int> &mystack,int num) { if(mystack.size()==0) { mysta ...

  5. delphi删除只读文件

    只读文件就是不能删除的文件,用DeleteFile函数对它来说是毫无意义的,要删除只读文件,只有先改变它的属性.如果你要删除一个文件,最好先作两个方面的考虑: (1)判断该文件的属性.可以用上面提到的 ...

  6. 2.4.1-Java语言基础(常量)

    2.4.1 常量 常量表示不能改变的数值. Java中常量的分类: 1,整数常量.全部整数 2,小数常量.全部小数 3,布尔型常量.较为特有,仅仅有两个数值.true false. 4,字符常量.将一 ...

  7. VC/MFC 使edit控件不能进行粘贴操作

    这里使用消息拦截的方法 BOOL PersonDlg::PreTranslateMessage(MSG* pMsg) { if (GetDlgItem(IDC_EDIT_USER_ID)->m_ ...

  8. 使用elk+redis搭建nginx日志分析平台(转)

    logstash,elasticsearch,kibana 怎么进行nginx的日志分析呢?首先,架构方面,nginx是有日志文件的,它的每个请求的状态等都有日志文件进行记录.其次,需要有个队列,re ...

  9. HealthKit教程 Swift版:锻炼信息

    原文:HealthKit Tutorial with Swift: Workouts 作者:Ernesto García 译者:Mr_cyz ) 欢迎回到我们的HealthKit系列教程! 在我们系列 ...

  10. vs2008编译QT开源项目--太阳神三国杀源码分析(三) 皮肤

    太阳神三国杀的界面很绚丽,界面上按钮的图标,鼠标移入移出时图标的变化,日志和聊天Widget的边框和半透明等效果,既可以通过代码来控制,也可以使用皮肤文件qss进行控制.下面我们分析一下三国杀的qss ...