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 several consecutive 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, but once 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
用全排列的方法来做。这我一開始还真没想到
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n,k,l,r;
int vis[500],a[500],tem[500],s[500]; void set(int len,int sum)
{
vis[sum] = 1;
if(len == k)
return ;
set(len+1,sum^tem[len]);
set(len+1,sum);
} int check()
{
memset(vis,0,sizeof(vis));
set(0,0);
for(int i = l; i<=r; i++)
if(!vis[i])
return 0;
return 1;
} void solve()
{
if(!check()) return ;
int i,j;
for(i = 0; i<k; i++)
s[i] = tem[i];
do
{
memset(vis,0,sizeof(vis));
for(i = 0; i<k; i++)
{
int ans = 0;
for(j = i; j<k+i; j++)
{
ans^=s[(j%k)];
vis[ans] = 1;
}
}
for(i = l; i<=128; i++)//a[i]最大100,所以不会超过128
if(!vis[i])
{
r = max(r,i-1);
break;
} }
while(next_permutation(s+1,s+k));
} void dfs(int now,int len)
{
if(len == k)
{
solve();
return ;
}
for(int i = now; i<n; i++)
{
tem[len] = a[i];
dfs(i+1,len+1);
}
} int main()
{
int i,j;
while(~scanf("%d%d%d",&n,&k,&l))
{
for(i = 0; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);//先排序,方便后面进行排列
r = l-1;
dfs(0,0);
if(r<l)
printf("0\n");
else
printf("%d\n",r);
} return 0;
}

HDU4876:ZCC loves cards的更多相关文章

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

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

  2. hdu 4876 ZCC loves cards(暴力)

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

  3. 多校训练赛2 ZCC loves cards

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

  4. HDOJ 4876 ZCC loves cards

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

  5. HDU 4876 ZCC loves cards _(:зゝ∠)_ 随机输出保平安

    GG,,,g艹 #include <cstdio> #include <iostream> #include <algorithm> #include <st ...

  6. HDU4876ZCC loves cards(多校题)

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

  7. hdu 5288 ZCC loves straight flush

    传送门 ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K ...

  8. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves s ...

  9. 2014---多校训练2(ZCC Loves Codefires)

    ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. ELK之日志查询、收集与分析系统

    项目由来 (1)开发人员不能登录线上服务器查看详细日志,经过运维周转费时费力 (2)日志数据分散在多个系统,难以查找与整合 (3)日志数据量巨大,查询速度太慢,无法满足需求 (4)无法全局掌控项目运行 ...

  2. 1.26 Python知识进阶 - 继承

    继承 继承(Inheritance)是面向对象的程序设计中代码重要的主要方法.继承是允许使用现有类的功能,并在无需重新改写原来的类的情况下,对这些功能进行扩展.继承可以避免代码复制和相关的代码维护等问 ...

  3. cc1.exe -fno-stack-protector

    # github.com/mattn/go-sqlite3 cc1.exe: error: unrecognized command line option "-fno-stack-prot ...

  4. NVM安装nodejs的方法

    安装nodejs方式有很多种. 第一种:官网下载  通过nodejs官网下载安装 ,但有个缺陷,不同版本的nodejs无法顺利的切换. 第二种: NVM安装  NVM可以帮助我们快速切换 node版本 ...

  5. Hadoop学习小结

    还在学校的时候,就知道Hadoop的存在了. 2012年在公司实习的时候,买了<Hadoop权威指南第2版>,大致看了下. 今年,抽空也大致喵了几眼. 最大的感悟就是:光看不做,还是不行. ...

  6. Quartz学习总结(1)——Spring集成Quartz框架

    一.Quartz简介 Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2SE应用程序相结合也可以单独使用.Quartz可以用来创建简 ...

  7. C++ Traits 技术

    Tarits.特性的复数. c++萃取技术就是指它. 实现方式是模板特化. STL中涉及到iterator的地方常常能用到它. gcc的STL与VS的STL略有区别. vs中下列代码,把鼠标放在ite ...

  8. Android开发工具之adt-bundle-windows

    adt-bundle-windows是非常久之前的android开发工具.是集成了ADT版本号的eclipse,可是里面并没有下载SDK.这个须要自己单独下载,这个工具适合刚開始学习的人使用. 由于刚 ...

  9. setting.system-全局属性的设定

    SystemProperties跟Settings.System 1 使用 SystemProperties.get如果属性名称以“ro.”开头,那么这个属性被视为只读属性.一旦设置,属性值不能改变. ...

  10. django 简单会议室预约(1)

    django 是python的一个web框架,为什么要用django,作者之前用过另一个框架flask,虽然flask比较简单很容易让人学,但是flask没有整体感,会让初学着茫然. 这里我们用dja ...