hdu 4876 ZCC loves cards
来源:互联网 发布:淘宝上买黄金可靠吗 编辑:程序博客网 时间:2024/05/16 01:50
ZCC loves cards
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1929 Accepted Submission(s): 503
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
镇海中学
Source
2014 Multi-University Training Contest 2
暴力+剪枝
#include <iostream>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <cmath>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <functional>#include <sstream>#include <iomanip>#include <cmath>#include <cstdlib>#include <ctime>//#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;#define INF 1e9#define MAXN 21#define maxn 30#define mod 1000000007#define eps 1e-7#define pi 3.1415926535897932384626433#define rep(i,n) for(int i=0;i<n;i++)#define rep1(i,n) for(int i=1;i<=n;i++)#define scan(n) scanf("%d",&n)#define scanll(n) scanf("%I64d",&n)#define scan2(n,m) scanf("%d%d",&n,&m)#define scans(s) scanf("%s",s);#define ini(a) memset(a,0,sizeof(a))#define out(n) printf("%d\n",n)ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int l,r,k,n;int a[maxn], tmp[maxn], save[maxn];int vis[200];void calmax(int cur,int sum) // 2 ^ k = 64枚举{vis[sum] = 1;if(cur == k) return ;calmax(cur + 1,sum ^ save[cur]);calmax(cur + 1,sum);}bool check(){ini(vis);calmax(0,0);for(int i = l;i <= r; i++) //当随意取也达不到当前r时,说明这组选法不满足,不用进入全排列{if(!vis[i]) return false;}return true;}void solve(){if(!check()) return;rep(i,k) tmp[i] = save[i];do //全排列计算,一次复杂度A(5,5) * (6 * 6 + 128){ini(vis);for(int i = 0;i < k; i++){int ans = 0;for(int j = i; j < k + i; j++){ans ^= tmp[j % k];vis[ans] = 1;}}for(int i = l;i <= 128; i++){if(!vis[i]){r = max(r,i-1);break;}}}while(next_permutation(tmp + 1, tmp + k));}void dfs(int cur,int num) //C(20,6)取数{if(num == k){solve();return;}for(int i = cur;i < n; i++){save[num] = a[i];dfs(i + 1,num + 1);}}int main(){#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);#endif while(~scanf("%d%d%d",&n,&k,&l)){rep(i,n) scan(a[i]);sort(a,a+n);r = l - 1;dfs(0, 0);if(r < l) puts("0");else out(r);}return 0;}
0 0
- 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(暴力)
- HDU 4876 ZCC loves cards(暴力剪枝)
- 【HDU】4876 ZCC loves cards 暴力
- hdu 4876 ZCC loves cards (搜索+剪枝)
- HDOJ 4876 ZCC loves cards
- hdu 4876 ZCC loves cards(暴力+剪枝)
- hdu 4876 ZCC loves cards(暴搜+剪枝)
- HDU 4876 ZCC loves cards【暴力+深搜+剪枝】
- [HDOJ 4876] ZCC loves cards [搜索]
- HDOJ 4876 ZCC loves cards(搜索)
- HDU4876 ZCC loves cards
- HDU4876:ZCC loves cards
- CDOJ-#855 分割包围(二分查找)
- Opencl图片旋转编写
- DNS解析
- 在Android平台上编译faad2
- 射频电路设计实录前言与第一章,目标市场分析
- hdu 4876 ZCC loves cards
- 使用Windbg 调试.Net程序
- 基于Chrome,foxfire(WeiKit内核)浏览器的密码安全控件插件开发(NPAPI)
- JavaFX文档(8)开始JavaFX之旅——理解JavaFX架构
- Redmine使用OpenLDAP认证
- [hdu 4899]14年多校第四场C Hero meet devil 状压DP
- android中菜单的使用
- web页面常用js验证方法
- HDU 1051 wooden sticks