Hdu4876: ZCC loves cards

Source: Internet
Author: User
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
7HintThe fully-arranged sort means XOR method was used in the first place.
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; int N, K, L, R; int vis [500], a [500], TEM [500], s [500]; void set (INT Len, int sum) {vis [Sum] = 1; if (LEN = k) return; Set (LEN + 1, sum ^ TEM [Len]); Set (LEN + 1, sum);} int check () {memset (VIS, 0, sizeof (VIS); Set (0, 0 ); for (INT I = L; I <= r; I ++) if (! Vis [I]) return 0; return 1;} void solve () {If (! Check () return; int I, j; for (I = 0; I <K; I ++) s [I] = TEM [I]; do {memset (VIS, 0, sizeof (VIS); for (I = 0; I <K; I ++) {int ans = 0; For (j = I; j <K + I; j ++) {ans ^ = s [(j % K)]; vis [ANS] = 1 ;}} for (I = L; I <= 128; I ++) // A [I] cannot exceed 100 if (! Vis [I]) {r = max (R, I-1); break;} while (next_permutation (S + 1, S + k);} void DFS (INT now, int Len) {If (LEN = k) {solve (); Return ;}for (INT I = now; I <n; I ++) {TEM [Len] = A [I]; DFS (I + 1, Len + 1) ;}} int main () {int I, j; while (~ Scanf ("% d", & N, & K, & L) {for (I = 0; I <n; I ++) scanf ("% d", & A [I]); sort (A, A + n); // sort first to facilitate L-1; DFS (0, 0); If (r <L) printf ("0 \ n"); else printf ("% d \ n", R) ;}return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.