Enumerative combination: determines whether l... r can be overwritten without considering the continuity. This is a huge reduction for random data.
Brute-force detection once
ZCC loves cards
Time Limit: 4000/2000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 1346 accepted submission (s): 335
Problem descriptionzcc loves playing cards. he has n magical cards and each has a number on it. he wants to choose K cards and place them around in any order to form a circle. he can choose any several
ConsecutiveCards the number of which is m (1 <= m <= K) to play a magic. the magic is simple that ZCC can get a number x = A1 127a2... when am, which AI means the number on the ith card he chooses. he can play the magic infinite times,
Once he begin to play the magic, he can't change anything in the card circle including the order.
ZCC has a lucky number L. ZCC want to obtain the number l ~ R by using one card circle. and if he can get other numbers which aren't in the range [L, R], it doesn' t matter. help him to find the maximal R.
Inputthe input contains several test cases. the first line in each case contains three integers N, K and L (K ≤ n ≤ 20, 1 ≤ k ≤ 6, 1 ≤ L ≤ 100 ). the next line contains N numbers means the numbers on the N cards. the ith number A [I] satisfies 1 ≤a [I] ≤100.
You can assume that all the test case generated randomly.
Outputfor each test case, output the maximal number R. And if l can't be obtained, output 0.
Sample Input
4 3 12 3 4 5
Sample output
7Hint ⊕ means xor
Author Zhenhai Middle School
Source2014 multi-university training Contest 2
Recommendwe have carefully selected several similar problems for you: 4881 4880 4879 4878 4877
Statistic | submit | discuss | note
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int n,k,m,a[30],save[30],have[30],R,L;bool vis[3000],cx[200];void ckMax(int num,int sum){vis[sum]=true;if(num==k) return ;ckMax(num+1,sum^save[num]);ckMax(num+1,sum);}bool ck(){ memset(vis,0,sizeof(vis)); ckMax(0,0); for(int i=L;i<=R;i++) { if(vis[i]==false)return false; } return true;}void CALU() { if (!ck()) return; for(int i=0;i<k;i++) have[i]=save[i]; do { memset(vis,0,sizeof(vis)); for(int i=0;i<k;i++) { int x=0; for(int j=0;j<k;j++) { x^=have[(i+j)%k]; vis[x]=true; } } for(int i=L;i<=L+k*k;i++) { if(vis[i]==false) break; R=max(R,i); } }while(next_permutation(have,have+k-1));} void dfs(int num,int id){if(num==k){CALU();return ;}for(int i=id;i<n;i++){save[num]=a[i];dfs(num+1,i+1);}}int main(){while(scanf("%d%d%d",&n,&k,&L)!=EOF){R=L-1;for(int i=0;i<n;i++)scanf("%d",a+i);sort(a,a+n);dfs(0,0);if(R<L) printf("0\n");else printf("%d\n",R);}return 0;}