HDU4876(深搜+剪枝+全排列)
来源:互联网 发布:网络问政的特点 编辑:程序博客网 时间:2024/06/06 09:29
ZCC loves cards
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3332 Accepted Submission(s): 821
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 severalconsecutive 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, butonce 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
镇海中学
Source
2014 Multi-University Training Contest 2
#include<stdio.h>#include<string.h>#include<algorithm> #include<iostream>using namespace std;const int maxn=1000;int n,k,l;int r;int a[maxn],tmp[maxn],tes[maxn];bool vis[maxn];void cal(int s,int num){if(num==k+1)return;vis[s]=true;cal(s^tmp[num],num+1);cal(s,num+1);} bool check(){memset(vis,false,sizeof(vis));cal(0,0);for(int i=l;i<=r;i++)if(!vis[i])return false;return true;}void work(){if(!check())return;for(int i=0;i<k;i++){tes[i]=tmp[i];}do{memset(vis,false,sizeof(vis));for(int i=0;i<k;i++){int s=0;for(int j=i;j<i+k;j++){s^=tes[j%k];vis[s]=1;}for(int j=l;j<110;j++){if(!vis[j]){r=max(r,j-1);break;}}}}while(next_permutation(tes,tes+k));}void dfs(int b,int s){if(s==k)work();for(int i=b;i<n;i++){tmp[s]=a[i];dfs(i+1,s+1);}}int main(){while(~scanf("%d%d%d",&n,&k,&l)){for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); r=l-1;dfs(0,0);if(r<l) printf("0\n"); else printf("%d\n",r);}return 0;}
阅读全文
0 0
- HDU4876(深搜+剪枝+全排列)
- hdu4876 深搜+(随机枚举剪枝)
- hdu4876 暴搜剪枝
- UVa 140 Bandwidth (枚举全排列&剪枝搜索)
- UVa 140 - Bandwidth(全排列+回溯剪枝)
- POJ2718 贪心算法(奇)+全排列剪枝(偶)
- 全排列 深搜dfs
- 计蒜客模拟赛5-补全等式;dfs全排列+剪枝
- (BestCoder Round #14) 1002 Harry And Dig Machine(状态压缩+DP;剪枝+搜索;全排列)
- 全排列 (深搜 DFS)
- 深搜--全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- JS编程-寻找字符串中出现最多的字符以及重复次数
- 2017/8/5训练日记(最短路径算法之Dijkstra算法和Bellman-Ford算法)
- 事务管理之事务的基本概念总览
- HDUOJ {A}+{B}
- POJ 2968 The Pilots Brothers' refrigerator(DFS)
- HDU4876(深搜+剪枝+全排列)
- mybatis级联映射
- 【react】利用shouldComponentUpdate钩子函数优化react性能以及引入immutable库的必要性
- django允许外部访问
- 常用HTML标签学习笔记1
- python系列之numpy模块学习
- 解决unity无法添加环境音效的问题,曲线调整深度理解。(最新版unity2017)
- python opencv入门 更多关于轮廓的函数(20)
- Palindrome Number