题目链接:hdu 4876 ZCC loves cards

题目大意:给出n,k,l,表示有n张牌,每张牌有值。选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值的亦或和。要求找到一个圈,使得L~R之间的数都能够得到,输出R。假设R < L输出0.

解题思路:暴力,首先预处理出来每种选取的亦或值,然后在该基础上从能够组成L的状态中挑选一个,L+1的状态中挑取一个,知道说总的挑取出全部状态中选中的牌的个数大于K为值,然后用全排序去查找最大的R。

#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm> using namespace std;
typedef long long ll;
const int maxn = 200;
const int maxc = 25;
const int maxs = 1<<20;
const int maxt = 20005; bool flag;
int ans, rec, dp[maxs+5];
int N, K, L, arr[maxc];
int vec[maxn][maxt], c[maxn]; inline int bitcount (int s) {
return s == 0 ? 0 : bitcount(s/2) + (s&1);
} void dfs (int d, int s, int val, int f) {
if (d == K + 1)
return; vec[val][c[val]++] = s; for (int i = f + 1; i < N; i++)
dfs (d+1, s|(1<<i), val^arr[i], i);
} void init () {
flag = true;
ans = rec = 0;
memset(c, 0, sizeof(c));
memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++)
scanf("%d", &arr[i]); dfs(0, 0, 0, -1);
} int check (int* a) {
int v[maxn];
memset(v, 0, sizeof(v)); for (int m = 1; m <= K; m++) {
int tmp = a[0];
for (int i = 1; i < m; i++)
tmp ^= a[i]; for (int i = 0; i < K; i++) {
v[tmp] = 1;
tmp ^= (a[i] ^ a[i+m]);
}
} int ans = L;
while (v[ans] && ans < maxn)
ans++;
return ans - 1;
} void judge (int s) {
int cnt = 0, a[2*maxn]; for (int i = 0; i < N; i++) {
if (s&(1<<i))
a[cnt++] = arr[i];
} sort(a + 1, a + cnt);
do {
for (int i = 0; i < cnt; i++)
a[i+cnt] = a[i]; ans = max(ans, check(a));
} while (next_permutation(a + 1, a + cnt));
}
/*
*/ void solve (int d, int s) {
int cnt = bitcount(s); rec = max(d, rec);
if (cnt >= K || d >= maxn) {
if (cnt == K) {
judge(s);
flag = false;
}
return;
} for (int i = 0; i < c[d]; i++) {
int s0 = (s | vec[d][i]);
if (dp[s0]) continue;
solve(d+1, s0);
dp[s0] = 1;
}
} int main () {
while (scanf("%d%d%d", &N, &K, &L) == 3) {
init();
solve(L, 0); if (flag)
ans = rec - 1;
printf("%d\n", ans < L ? 0 : ans);
}
return 0;
}

hdu 4876 ZCC loves cards(暴力)的更多相关文章

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

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

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

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

  3. HDOJ 4876 ZCC loves cards

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

  4. hdu 4873 ZCC Loves Intersection(大数+概率)

    pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...

  5. 多校训练赛2 ZCC loves cards

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

  6. HDU 4873 ZCC Loves Intersection(可能性)

    HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...

  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 4882 ZCC Loves Codefires(数学题+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...

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

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

随机推荐

  1. bzoj1497(最小割)

    传送门:最大获利 题意:建立n个中转站,每个花费P[i],有m个用户,使用Ai和Bi中转站可获利Ci,问最终建立哪几个中转站使获利最大? 分析:根据最大权闭合图建图,用户群和中转站为带权的点集,用户群 ...

  2. ActivityGroup简单介绍

    ActivityGroup简单介绍 1.ActivityGroup的核心就是继承了该类,可以通过getLocalActivityManager()得到一个LocalActivityManager 如, ...

  3. asp.net操作word的表格

    近日开发中用户要求实现导出数据为Word,本来想使用html保存为word的实现,但因用户要求样式很高,使用html不好控制,并且导出中包括图片,使用页面导出时图片还是一个路径,不能把图片包括在wor ...

  4. Driver 初始化顺序

    Linux系统使用两种方式去加载系统中的模块:动态和静态. 静态加载:将所有模块的程序编译到Linux内核中,由do_initcall函数加载 核心进程(/init/main.c)kernel_ini ...

  5. 基于.net开发chrome核心浏览器【二】

    原文:基于.net开发chrome核心浏览器[二] 一: 上一篇的链接: 基于.net开发chrome核心浏览器[一] 二: 相关资源介绍: chrome Frame: 让IE有一颗chrome的心, ...

  6. Kafka学习(一)配置及简单命令使用

    一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,当中涉及到的相关概念例如以下: Kafka中传递的内容称为message(消息),message 是通过topic ...

  7. 鸽巢原理应用-分糖果 POJ 3370 Halloween treats

    基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...

  8. ASP.NET——验证码的制作

            我们在登陆站点,发表博客或者提交评论的时候,常常会遇到填写验证码这一项,当时感觉挺奇妙的样子,最终在牛腩新闻公布系统里接触到了,在这里小小的总结下.         用到的东东有三个: ...

  9. 树形dp专辑

    hdu 2196 http://acm.hdu.edu.cn/showproblem.php?pid=2196 input 5//5个结点 1 1//表示结点2到结点1有一条权值为1的边 2 1//表 ...

  10. Python学习路径8——Python对象2

    1.标准型运营商 1.1对象值对照 比较运算符用于如果相同类型的对象是相等.所有的内建类型的是在比较操作中支持,返回布尔比较操作值True 或 False. <span style=" ...