2014 Multi-University Training Contest 2 ZCC loves cards

3 篇文章 0 订阅
#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值