HDu 4876(2014多校第二场 ZCC loves cards)
来源:互联网 发布:mysql select 锁表 编辑:程序博客网 时间:2024/06/05 10:16
ZCC loves cards
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1868 Accepted Submission(s): 483
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.
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.
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 12 3 4 5
Sample Output
7Hint⊕ means xor
Author
镇海中学
已被中学生虐惨。
该题正解是爆搜,如果预处理出状态的化会比直接爆搜慢很多,而且剪枝的关键在于先用2的n次方不考虑顺序,如果这种情况下都比前面最小值小,则这种情况不搜索。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[400004],b[55],c[55],d[55];bool dp[129];int tot;int s[7];void solve(int n,int k,int sum){ dp[sum]=1; if(n==k) return ; solve(n+1,k,sum); solve(n+1,k,sum^b[c[n]]);}int pp;bool vis[8];void quanpai(int n,int k,int l){ if(n==k){ int i,j; memset(dp,0,sizeof(dp)); for(i=0;i<k;i++){ if(i==0) s[i]=b[c[d[i]]]; else{ s[i]=s[i-1]^b[c[d[i]]]; } } s[k]=0; for(i=1;i<k;i++){ for(j=0;j<i;j++){ dp[s[i]]=1; dp[s[j]]=1; dp[s[k-1]^s[i]]=1; dp[s[j]^s[i]]=1; dp[s[k-1]^s[i]^s[j]]=1; } } for(i=l;i<128;i++){ if(!dp[i]) break; } if(pp<i-1) pp=i-1; return ; } int i; for(i=0;i<k;i++){ if(!vis[i]){ vis[i]=1; d[n]=i; quanpai(n+1,k,l); vis[i]=0; } }}void dfs(int n,int k,int l,int pos,int ss){ int i,j; if(n==k){ memset(dp,0,sizeof(dp)); solve(0,k,0); for(i=l;i<=pp;i++){ if(!dp[i]) return ; } memset(vis,0,sizeof(vis)); quanpai(0,k,l); return ; } for(i=pos+1;i<=ss;i++){ c[n]=i; dfs(n+1,k,l,i,ss); } return ;}int main(){ int i,n,k,l; while(scanf("%d%d%d",&n,&k,&l)!=EOF){ for(i=1;i<=n;i++) scanf("%d",&b[i]); sort(b+1,b+1+n); if(k>n) k=n ; pp=l-1; dfs(0,k,l,0,n); if(pp<l) printf("0\n"); else printf("%d\n",pp); }}
0 0
- HDu 4876(2014多校第二场 ZCC loves cards)
- HDU 4876 ZCC loves cards (2014多校联合训练第二场1005) 解题报告(暴力+剪枝)
- hdu 4876 ZCC loves cards 多校第二场 暴力+剪枝
- HDU 4882 ZCC Loves Codefires(2014多校第二场1011)(贪心)
- HDU 4876 ZCC loves cards
- HDU-4876-ZCC loves cards
- hdu 4876 ZCC loves cards
- HDU 4876 ZCC loves cards
- HDU 4876 ZCC loves cards
- hdu 4882 ZCC Loves Codefires 2014年多校联合第二场
- hdu 4876 ZCC loves cards(暴力+剪枝)
- hdu 4876 ZCC loves cards(暴搜+剪枝)
- 【HDU 4876多校】ZCC loves cards【搜索】
- hdu 4876 ZCC loves cards(暴力)
- HDU 4876 ZCC loves cards(暴力剪枝)
- 【HDU】4876 ZCC loves cards 暴力
- hdu 4876 ZCC loves cards (搜索+剪枝)
- HDOJ 4876 ZCC loves cards
- 不同App共享KeyChain数据
- java学习日记05——java中的浮点数剖析
- 学习历程之HTML第二篇
- 拓扑排序
- Sybase identity 字段
- HDu 4876(2014多校第二场 ZCC loves cards)
- POJ_2586_Y2K Accounting Bug_英语、贪心
- 集合框架(泛型类)
- UVA 488 Triangle Wave
- POJ 2531 Network Saboteur (搜索)
- OCP 1Z0 053 227
- 最小生成树-Prim算法和Kruskal算法
- JS感悟
- Vector的使用