Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4876
Test instructions: give you n,l,k three number, n is the number of n, choose the number of K, and then
The k number consists of a ring, which can be selected from this ring for the number of consecutive 1-k to be different or
, the resulting value is filled to the back of L, so that there is a number r so that all the whole l-r between
Integers are these XOR and fill, seeking the largest r, perhaps expressed less clearly, in fact
is to find a maximum r, so that all the numbers of the given l to this r can be
XOR and expression come out, note that XOR and requirements are consecutive numbers of different or.
Analysis: This problem I saw a long time no idea, read Daniel's blog for a long time did not understand, the brain
Relatively stupid knowledge is not strong, is this, this problem should be the point of time, here
There is an optimization, first of all, by the usual C (n,k) combination, and then in
The number of the K to be ordered, sorting can be used next_permutation () this
function, I will ask for an R for every sequence I get, and finally take the largest r, the optimization point is
Assuming that there is currently an r, when taking the second combination, first press the number of K to avoid continuous
The number of l-r, whether it can achieve the effect of all the numbers represented by the current
If it doesn't come out, I don't have to calculate the number of K combinations, because k<=6
So it's not necessary to have a continuous XOR and not take too much time, so it's time to solve the problem.
Then present the code:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace Std;
const int MAXK=100+10;
const int MAXN=200+10;
int tmp[maxk],num[maxn],test[maxn],l,r,n,k;
BOOL VISIT[MAXN];
void set (int sum,int now)
{
if (now==k+1) return;
Visit[sum]=true;
Set (SUM^TMP[NOW],NOW+1);
Set (SUM,NOW+1);
}
BOOL Judge ()
{
memset (visit,false,sizeof (visit));
Set (0,0);
for (int i=l;i<=r;i++)
if (!visit[i])
return false;
return true;
}
void Control ()
{
if (!judge ())
Return
for (int i=0;i<k;i++)
{
Test[i]=tmp[i];
}
do{
memset (visit,false,sizeof (visit));
for (int i=0;i<k;i++)
{
int sum=0;
for (int j=i;j<i+k;j++)
{
SUM^=TEST[J%K];
Visit[sum]=true;
}
for (int j=l;j<110;j++)
if (!visit[j])
{
R=max (r,j-1);
Break
}
}
}while (Next_permutation (test,test+k));
}
void Dfs (int con,int now)
{
if (now==k)
Control ();
for (int i=con;i<n;i++)
{
Tmp[now]=num[i];
DFS (I+1,NOW+1);
}
}
int main ()
{
while (~SCANF ("%d%d%d", &n,&k,&l))
{
for (int i=0;i<n;i++)
scanf ("%d", &num[i]);
Sort (num,num+n);
R=L-1;
DFS (0,0);
if (r<l)
printf ("0\n");
Else
printf ("%d\n", R);
}
return 0;
}
HDU 4876 ZCC loves cards "violence + deep Search + pruning"