您的位置:首页 > 大数据 > 人工智能

2014 Multi-University Training Contest 2 ZCC loves cards

2014-07-25 12:50 435 查看
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <climits>

#define MAXN 100005
#define eps 1e-5
#define MOD 1000000007

#define test

#define For(i,m,n) for(int i=(m);i<(n);i++)
#define vecfor(iter,a) for(vector<int>::iterator iter=a.begin();iter!=a.end();iter++)
#define rep(i,m,n) for(int i=(m);i<=(n);i++)
#define LL long long

/*author birdstorm*/
using namespace std;
const double pi=acos(-1.0);

template<class T>
inline bool read(T &n){
T x = 0, tmp = 1; char c = getchar();
while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
if(c == EOF) return false;
if(c == '-') c = getchar(), tmp = -1;
while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
n = x*tmp;
return true;
}

template <class T>
inline void write(T n) {
if(n < 0) {
putchar('-');
n = -n;
}
int len = 0,data[20];
while(n) {
data[len++] = n%10;
n /= 10;
}
if(!len) data[len++] = 0;
while(len--) putchar(data[len]+48);
}

int ans; int a[220];
void dfs(int *a, int *b, int n, int m, int l, int &ans, int depth, int pos, int calc){
if(depth==m){
if(calc<=ans) return;
bool used[130]={false};
for(int i=1; i<(1<<m);i++){
int x=0;
for(int j=0; j<m; j++){
if((1<<j)&i){
x^=b[j];
}
}
if(x>=l) used[x-l]=true;
}
for(int i=l; i<=ans; i++){
if(!used[i-l]) return;
}
int sta1[10], sta2[10], sta[20];
for(int m=1; m<(1<<depth); m++){
int ret=0;
int top1=0, top2=0, top=0;
for(int u=0; u<depth; u++){
if((1<<u)&m){
ret^=b[u];
sta1[top1++]=b[u];
}
else{
sta2[top2++]=b[u];
}
}
if(ret==l){
sort(sta1,sta1+top1);
do{
top=0;
for(int u=0; u<top1; ++u) sta[top++]=sta1[u];
sort(sta2,sta2+top2);
do{
top=top1;
for(int u=0; u<top2; ++u) sta[top++]=sta2[u];
for(int u=0; u<depth; ++u) sta[u+depth]=sta[u];
bool vis[130]={false};
for(int len=1; len<=depth; len++){
for(int start=0; start<depth; start++){
int ss=0;
for(int g=0; g<len; g++){
ss^=sta[g+start];
}
if(ss>=l) vis[ss-l]=true;
}
}

int u;

for(u=0; u<130; u++){
if(!vis[u]) break;
}

ans=max(ans,l+u-1);
}while(next_permutation(sta2,sta2+top2));
}while(next_permutation(sta1,sta1+top1));
}
}
return;
}
else For(i,pos+1,n){
b[depth]=a[i];
dfs(a,b,n,m,l,ans,depth+1,i,calc|a[i]);
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("/home/acm/code/output.txt","w",stdout);

int n, m, l;
while(read(n)&&read(m)&&read(l)){
For(i,0,n) read(a[i]);
ans=l-1;
int b[30];
dfs(a,b,n,m,l,ans,0,-1,0);
if(ans == l-1) printf("0\n");
else  printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐