HDU 4876 ZCC loves cards _(:зゝ∠)_ 随机输出保平安
GG,,,g艹
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;
vector<int>G[21][7];//G[i][j] 表示n=i k=j的情况下 二进制的状态
int n, k, l;
int a[21], d[6], val[6];
int vis[150], tim;
int work(int x){
int i = 0, j = 0;
while(x) {
if(x&1) d[i++] = j;//a[j]
j++;
x>>=1;
}
int ans = 0;
do
{
memset(val, 0, sizeof val);
tim ++;
int st = 0;
for(int num = 0; num < k; num++) {
i = st; j = 0;
while(1) {
val[j] ^= a[d[i]];
vis[val[j]] = tim;
i++; j++;if(i>=k)i=0;
if(i==st)break;
}
st++;
}
for(i = l; ; i++)
if(vis[i]!=tim)
{
ans = max(ans, (i-1)>=l? (i-1):0);
break;
}
} while (next_permutation(d + 1, d + k));
return ans;
}
void dfs(int dep, int cnt, int num) {
if (dep > 20 || cnt > 6) return ;
G[dep][cnt].push_back(num);
dfs(dep + 1, cnt + 1, num | (1 << dep));
dfs(dep + 1, cnt, num);
} struct Node {
int cnt, idx;
bool operator < (const Node &rhs) const {
return cnt > rhs.cnt;
}
}; Node qq[24];
int b[24]; int cmp(int a, int b) {
return a > b;
} int main(){
int i, j;
for(i = 1; i <= 20; i++)
for(j = 1; j <= 6; j++) G[i][j].clear();
dfs(0, 0, 0);
tim = 100;
while(~scanf("%d %d %d",&n, &k, &l)) {
for(i = 0; i < n; i++)scanf("%d",&a[i]); int ans = 0, siz = (int)G[n][k].size();
if (siz <= 12000) {
for (int i = 0; i < siz; ++i) {
int cur = G[n][k][i];
ans = max(ans, work(cur));
}
} else if (siz <= 24001) {
for (int i = 1; i < siz; i += 2) {
int cur = G[n][k][i];
ans = max(ans, work(cur));
}
} else {
for (int i = 0; i < siz; i += 3) {
int cur = G[n][k][i];
ans = max(ans, work(cur));
}
} printf("%d\n",ans);
}
return 0;
}
HDU 4876 ZCC loves cards _(:зゝ∠)_ 随机输出保平安的更多相关文章
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...
- hdu 4876 ZCC loves cards(暴力)
题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...
- HDOJ 4876 ZCC loves cards
枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝. 通过检測的暴力计算一遍 ZCC loves cards Time Limit: 4000/2000 MS (Ja ...
- hdu 4873 ZCC Loves Intersection(大数+概率)
pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...
- 多校训练赛2 ZCC loves cards
ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4873 ZCC Loves Intersection(可能性)
HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...
- hdu 4882 ZCC Loves Codefires(数学题+贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...
- hdu 5288 ZCC loves straight flush
传送门 ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves s ...
随机推荐
- Centos6.5搭建bugzilla
一.安装httpd. mod_ssl. mysql-server . mysql .php-mysql . gcc . perl* . mod-perl-devel [root@localhost ~ ...
- 设计模式(十)享元模式Flyweight(结构型)
设计模式(十)享元模式Flyweight(结构型) 说明: 相对于其它模式,Flyweight模式在PHP实现似乎没有太大的意义,因为PHP的生命周期就在一个请求,请求执行完了,php占用的资源都被释 ...
- linux c coding style
Linux kernel coding style This is a short document describing the preferred coding style for the lin ...
- 基于visual Studio2013解决C语言竞赛题之0604二维数组置换
题目
- Android ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to register to receive intents
ReceiverCallNotAllowedException mContext.registerReceiver()不能在BroadcastReceiver的onReceive()里面调用 可以通过 ...
- haroxy hdr
ACL derivatives :ACL的衍生物 hdr([<name>[,<occ>]]) : exact string match 字符串精确匹配 hdr_beg([< ...
- linux i2c驱动架构-dm368 i2c驱动分析
linux i2c驱动架构-dm368 i2c驱动分析 在阅读本文最好先熟悉一种i2c设备的驱动程序,并且浏览一下i2c-core.c以及芯片提供商的提供的i2c总线驱动(i2c-davinc ...
- 【cocos2d-x】3.0使用cocos-console创建,编,部署游戏
原文地址:http://fengchenluoyu.duapp.com/272.html cocos2d-x 3.0開始添加了一个cocos-console组件,它位于cocos2d-x 3.0的to ...
- 11181 - Probability|Given
N friends go to the local super market together. The probability of their buying something from them ...
- 如何查看VS中预设的路径变量
类似"$(VCInstallDir)"之类的变量查询方法为:打开VS命令行提示窗口,输入 Set 命令. VS中“Tool” - “Visual Studio Command Pr ...