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. css 兼容性前缀

    一.不同浏览器内核下的书写规则 二:transform  具体变性中心基点  transform-origin  默认情况下  rotate旋转.scale缩放.translate位移.矩阵matri ...

  2. Linux 常用解压缩归档命令

    linux 常见压缩.归档工具 创建压缩工具 压缩工具 后缀 描述 compress/uncompress .Z 早期工具,现在不常见了 gzip/gunzip .gz 进几年比较火的工具 bzip2 ...

  3. mobx项目创建 + mobx项目流程代码

    一. 安装mobx 1. react 安装并 reject抽离配置 1. 全局安装 create-react-app 这个脚手架 npm/cnpm i create-react-app -g yarn ...

  4. Express框架是什么

    Express框架是什么 一.总结 1.express框架:基于node.js的web应用框架,可快速搭建一个完整功能的网站,丰富的HTTP工具以及来自Connect框架的中间件随取随用. 二.Exp ...

  5. 4.Windows下安装ZooKeeper

    转自:https://www.cnblogs.com/mstmdev/p/5612791.html 官方主页: https://zookeeper.apache.org/     选择合适的镜像地址下 ...

  6. web自动化测试 Selenium2 Java自动化测试实战9_3

    driver.findElement(By.id("idInput")).sendKeys("哈哈"); driver.findElement(By.id(&q ...

  7. 【2017 Multi-University Training Contest - Team 7 && hdu 6121】Build a tree

    [链接]点击打开链接 [题意] 询问n个点的完全k叉树,所有子树节点个数的异或总和为多少. [题解] 考虑如下的一棵k=3叉树,假设这棵树恰好有n个节点. 因为满的k叉树,第i层的节点个数为k^(i- ...

  8. js进阶 13-9/10 jquery如何实现三级列表

    js进阶 13-9/10 jquery如何实现三级列表 一.总结 一句话总结:用的是定位,父标签相对定位,子标签就可以绝对定位了,绝对定位的孩子还是可以设置绝对定位.用toggle设置子菜单显示和隐藏 ...

  9. Validation failed for query for method public abstract boxfish.bean.Student boxfish.service.StudentServiceBean.find(java.lang.String)!

    转自:https://blog.csdn.net/lzx925060109/article/details/40323741 1. Exception in thread "main&quo ...

  10. iOS_02_第一个C语言程序(理解编译、连接、运行)

    一.开发工具的选择 1. 可以用来写代码的工具:记事本.ULtraEdit.Vim.Xcode等. 2. 选择XCode的原因:苹果公司官方提供的开发利器.简化开发的工程.有高亮显示功能. 3. 使用 ...