hdu 4876 ZCC loves cards 2014 Multi-University Training Contest 2
2014-07-25 17:30
585 查看
ZCC loves cards
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1234 Accepted Submission(s): 301
Problem Description
ZCC 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 consecutive cards 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⊕a2...⊕am, which ai means the number on the ith card he chooses. He can play the magic infinite times, but 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.
Input
The 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.
Output
For each test case, output the maximal number R. And if L can’t be obtained, output 0.
Sample Input
4 3 1 2 3 4 5
Sample Output
7 Hint ⊕ means xor
Author
镇海中学
Source
2014 Multi-University Training Contest 2
Recommend
We have carefully selected several similar problems for you: 4881 4880 4879 4878 4877
官方思路:
说难不难,说水不水的题,做的很无语。照着官方思路敲就可以了,过是没有问题的,有大神优化到90+ms,有兴趣的可以搞搞,个人认为没必要做成那样。
敲代码的时候自己做了组优化,结果直接导致我查了一下午错 。自己坑自己能怪谁呢
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int p[25],a[25]; int res[333]; int v[333]; int ans,n,k,l; void work2() { do{ memset(v,0,sizeof(v)); for(int i=0;i<k;i++){ int t=0; int s=0; while(t<k){ int q=t+i; q%=k; s^=a[p[q]]; v[s]++; t++; } for(int j=l;;j++){ if(v[j])continue; else{ ans=max(ans,j-1); break; } } } }while(next_permutation(p+1,p+k)); } void work(int cnt,int s) { if(cnt==k) return; res[s]=1; int d=s^a[p[cnt]]; res[d]=1; work(cnt+1,s); work(cnt+1,d); } void dfs(int cnt) { if(cnt==k){ memset(res,0,sizeof(res)); work(0,0); for(int i=l;;i++){ if(res[i]) continue; else if(i-1>ans) work2(); return; } } int s=cnt ?p[cnt-1]+1:0; for(int i=s;i<n;i++){ p[cnt]=i; dfs(cnt+1); } } int main() { while(scanf("%d%d%d",&n,&k,&l)!=EOF){ for(int i=0;i<n;i++){ scanf("%d",&a[i]); memset(p,0,sizeof(p)); } ans=0; dfs(0); if(ans<l) printf("0\n"); else printf("%d\n",ans); } return 0; }
相关文章推荐
- 【2014 Multi-University Training Contest 2 1002】/【HDU 4873】 ZCC Loves Intersection
- 2014 Multi-University Training Contest 2 ZCC loves cards
- 【2014 Multi-University Training Contest 2 1002】/【HDU 4873】 ZCC Loves Intersection
- 【暴力+优化】【2014 Multi-University Training Contest 2】ZCC loves cards
- 【2014 Multi-University Training Contest 2 1002】/【HDU 4873】 ZCC Loves Intersection
- 2014 Multi-University Training Contest 2 ZCC loves cards
- hdu4882 ZCC Loves Codefires 2014 Multi-University Training Contest 2
- 【模拟+hash+并查集】2014 Multi-University Training Contest 2|HDU_4879 ZCC loves march
- 【贪心】【2014 Multi-University Training Contest 2】1011 ZCC Loves Codefires
- 2014 Multi-University Training Contest 2 1011 ZCC Loves Codefires 解题报告
- 2014 Multi-University Training Contest 2---ZCC Loves Codefires
- Hdu4882 - ZCC Loves Codefires - 贪心(2014 Multi-University Training Contest 2-1011)
- 2014 Multi-University Training Contest 2 - 1011 / hdu 4882 ZCC Loves Codefires
- 【2014 Multi-University Training Contest 2 1002】 ZCC Loves Intersection
- 【HDU 2014 Multi-University Training Contest 1 1002】/【HDU 4862】Jump
- hdu 4911 Inversion 2014 Multi-University Training Contest 5
- 【HDU 2014 Multi-University Training Contest 1 1002】/【HDU 4862】Jump
- 2014 Multi-University Training Contest 3 1007 && HDU 4893 Wow! Such Sequence ! (线段树)
- hdu 4970 Killing Monsters 策略O(n)/线段树O(nlogn)+快速读入 2014 Multi-University Training Contest 9-1011
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )