## hdu4876(dfs取数字组合+剪枝）

``````/*
* @Author: biggf
* @Date:   2018-07-05 10:42:50
* @Last Modified by:   biggf
* @Last Modified time: 2018-07-05 13:26:38
*/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int n,k,l;
int a[105];
int r,num;
int vis[2005];
int set[105];

int judge()
{
int i=l;
while(vis[i])i++;
if((l<=(i-1)))
return i-1;
else return 0;
}

void getset(int index,int num)
{
vis[num]=1;
if(index==k)
{
return ;
}
getset(index+1,num^set[index]);
getset(index+1,num);
}

int f=0;
int s2[300];
void solve()
{
memset(vis,0,sizeof vis);
getset(0,0);
int tmp=judge();
if(tmp<r)return;//一个关键剪枝
memset(vis,0,sizeof vis);
for(int i=0;i<k;i++)s2[i]=set[i];
num=0;
do{
memset(vis,0,sizeof vis);
for(int i=0;i<k;i++)
{
num=0;
for(int j=0;j<k;j++)
{
num^=s2[(j+i)%k];
vis[num]=1;
}
}
r=max(r,judge());
}while(next_permutation(s2,s2+k-1));
}

void dfs(int index,int cnt)
{
if(cnt==k)
{
solve();
return;
}
if(index>=n)return;
set[cnt]=a[index];
dfs(index+1,cnt+1);
dfs(index+1,cnt);
return;
}

int main()
{

while(scanf("%d%d%d",&n,&k,&l)!=EOF)
{
r=0;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
sort(a,a+n);
dfs(0,0);
printf("%d\n",r);
}
return 0;
}

/*

5 5 18
1 18 10 2  20
20 5 18
1 2 3 4  5 6 7 8 9 10 11 12 13 14 15 17 16 18 19 20

*/``````