ZCC loves cards

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 828    Accepted Submission(s): 184

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

 
Author
镇海中学
 
Source
 
Recommend
We have carefully selected several similar problems for you:  4882 4881 4880 4879 4878 
 
搜索
首先找到k个元素后,枚举这k个元素的所有子集,看能不能超过当前得到的最大的R,如果不能,就没有必要在检查
我们容易发现 假如要选出3个元素则编号为1 2 3   2 3 1   3 1 2 这三种排列在检查时是一样的因此枚举全排列时只需要枚举全排列的1 / k即可
最后一个剪枝是 把a数组事先按从大到小排列,若枚举的第一个元素的将所有位置1都无法超过当前最大值,则没有必要从这个元素枚举下去
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue> using namespace std; #define read() freopen("sw.in", "r", stdin) const int MAX_N = ;
const int MAX = ( << );
int N, K, L;
struct node {
int st[];
bool operator < (const node &rhs) const {
for (int i = ; i < K; ++i) {
if (st[i] != rhs.st[i]) return st[i] < rhs.st[i];
}
return ;
}
}; int x[MAX_N];
bool vis[MAX];
int ele[MAX_N];
int _max;
int len = ;
node p[]; int cal(int n) {
int ret = ;
if (n == ) ret = ;
while (n > ) {
++ret;
n >>= ;
} return ( << ret) - ;
} void check() {
int t = , _max1 = ;
/*for (int i = 0; i < K; ++i) printf("%d ", ele[i]);
printf("\n");*/
memset(vis, , sizeof(vis));
int cnt = ;
for (int s = ; s < ( << K); ++s) {
t = ;
for (int i = ; i < K; ++i) {
if (s >> i & ) {
t ^= ele[i];
}
}
if (!vis[t]) {
vis[t] = ;
if (t >= L && t <= _max + ) ++cnt;
} _max1 = max(_max1, t);
} if (_max1 <= _max || cnt < (_max + - L)) return; for (int i = ; i < len; ++i) {
memset(vis, , sizeof(vis));
cnt = ;
for (int start = ; start < K; ++start) {
int v;
for (int l = ; l <= K; ++l) {
v = ;
for (int pos = start, num = ; num <= l; pos = (pos + ) % K, ++num)
v ^= ele[ p[i].st[pos] ];
if (!vis[ v ]) {
vis[v] = ;
if (v >= L && v <= _max + ) ++cnt;
}
} }
int k = _max + ;
if (cnt < (_max + - L)) continue;
while (vis[k] == ) ++k;
_max = max(_max, k - );
} } void dfs(int id, int num) {
if (num >= K) {
//printf("fuck\n");
check();
return ;
}
if (id >= N) return ; if (num == && cal(x[id]) <= _max) return;
ele[num] = x[id];
dfs(id + , num + );
dfs(id + , num);
} int main()
{
//read();
while (scanf("%d%d%d", &N, &K, &L) != EOF) {
for (int i = ; i < N; ++i) scanf("%d", &x[i]);
set <node> Set;
len = ;
int id[] = {, , , , , };
sort(x, x + N, greater<int>());
_max = L - ; do {
node st;
for (int i = ; i < K; ++i) st.st[i] = id[i];
if (Set.find(st) != Set.end()) continue;
// for (int i = 0; i < K; ++i) printf("%d ", id[i]);
//printf("\n");
for (int i = ; i < K; ++i) p[len].st[i] = id[i];
len++;
for (int i = ; i < K; ++i) {
for (int m = , j = i; m < K; ++m, j = (j + ) % K) {
st.st[m] = id[j];
}
Set.insert(st);
} }while (next_permutation(id, id + K)); dfs(, );
printf("%d\n", _max < L ? : _max); }
//cout << "Hello world!" << endl;
return ;
}
 

hdu 4876的更多相关文章

  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. hdu 4876(剪枝+暴力)

    题意:给定n,k,l,接下来给出n个数,让你从n个数中选取k个数围成一圈,然后从这k个数中随意选出连续的m(m>=1&&m<=k)个数进行异或后得到[l,r]区间的所有值, ...

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

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

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. 《Java设计模式》之解释器模式

    解释器模式是类的行为模式.给定一个语言之后,解释器模式能够定义出其文法的一种表示,并同一时候提供一个解释器. client能够使用这个解释器来解释这个语言中的句子. 解释器模式的结构 以下就以一个示意 ...

  2. Java进程堆外内存(off heap)大小

    一.使用ByteBuffer.allocateDirect分配的off heap内存大小 本机进程 在Jvisualvm中安装 Mbeans插件.然后查看java.nio/BufferPool/dir ...

  3. 微信前端js sdk以外的开发

    此时页面中就会出现刚才我画红圈部分的工具条. 这个工具条再加上上面的标题栏工具条. 极大的降低了可视区域的面积. 是否能将它去掉呢?答案是能够的.增加以下代码就能够去掉微信中以下的工具条: docum ...

  4. Linux安装MATLAB

    Linux下的MATLAB在2013a及以后的版本中,就不再支持32位机了.所以32位Linux系统无法安装2013a及以后版本.[1] Linux下安装MATLAB时,需要先配置好JRE,可以参考: ...

  5. 神经网络结构设计指导原则——输入层:神经元个数=feature维度 输出层:神经元个数=分类类别数,默认只用一个隐层 如果用多个隐层,则每个隐层的神经元数目都一样

    神经网络结构设计指导原则 原文   http://blog.csdn.net/ybdesire/article/details/52821185   下面这个神经网络结构设计指导原则是Andrew N ...

  6. P2453 [SDOI2006]最短距离 dp

    自己想出来了!这个dp比较简单,而且转移也很简单,很自然,直接上代码就行了. 题干: 一种EDIT字母编辑器,它的功能是可以通过不同的变换操作可以把一个源串X [l..m]变换为新的目标串y[1..n ...

  7. django入门与实践 3-1 环境搭建

    Python 2.7 .Django对2.7.3.5.3.4都是支持的. https://www.djangoproject.com/download/ django对python的兼容情况 pip安 ...

  8. RegisterAttached 两种绑定方式

    RegisterAttached 含义:使用指定的属性名称.属性类型和所有者类型注册附加属性 绑定方式:C#绑定.WPF绑定 例:需求DataViewModel为DataView的VM层,在DataV ...

  9. codevs1225八数码难题(搜索·)

    1225 八数码难题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description Yours和zero在研究A*启 ...

  10. codevs1669 运输装备(背包dp)

    1669 运输装备  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond   题目描述 Description 德国放松对英国的进攻后,把矛头指向了东北——苏联 ...