zoukankan      html  css  js  c++  java
  • HDOJ 4876 ZCC loves cards


    枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝.

    通过检測的暴力计算一遍


    ZCC loves cards

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1346    Accepted Submission(s): 335


    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
     

    Recommend
    We have carefully selected several similar problems for you:  4881 4880 4879 4878 4877 
     

    Statistic | Submit | Discuss | Note



    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    int n,k,m,a[30],save[30],have[30],R,L;
    bool vis[3000],cx[200];
    
    void ckMax(int num,int sum)
    {
    	vis[sum]=true;
    	if(num==k) return ;
    	ckMax(num+1,sum^save[num]);
    	ckMax(num+1,sum);
    }
    
    bool ck()
    {
     	memset(vis,0,sizeof(vis));
     	ckMax(0,0);
     	for(int i=L;i<=R;i++)
     	{
     		if(vis[i]==false)	return false;
     	}
     	return true;
    }
    
    void CALU() 
    {  
        if (!ck()) return;  
        for(int i=0;i<k;i++)
        	have[i]=save[i];
        do
        {
        	memset(vis,0,sizeof(vis));
        	for(int i=0;i<k;i++)
        	{
        		int x=0;
        		for(int j=0;j<k;j++)
        		{
        			x^=have[(i+j)%k];
        			vis[x]=true;	
        		}
        	}
        	for(int i=L;i<=L+k*k;i++)
        	{
        		if(vis[i]==false) break;
        		R=max(R,i);
        	}
        }while(next_permutation(have,have+k-1));
    }      
    
    void dfs(int num,int id)
    {
    	if(num==k)
    	{
    		CALU();
    		return ;
    	}
    	for(int i=id;i<n;i++)
    	{
    		save[num]=a[i];
    		dfs(num+1,i+1);
    	}
    }
    
    int main()
    {
    	while(scanf("%d%d%d",&n,&k,&L)!=EOF)
    	{
    		R=L-1;
    		for(int i=0;i<n;i++)
    			scanf("%d",a+i);
    		sort(a,a+n);
    		dfs(0,0);
    		if(R<L) printf("0
    ");
    		else printf("%d
    ",R);
    	}
    	return 0;
    }


  • 相关阅读:
    jQuery Timer 实现的新邮件提醒
    在 jquery repeater 中添加设置日期,下拉,复选框等控件
    jquery repeater 完成 QQ 邮箱邮件分组显示功能
    Ajax 与 WebService 之间日期等数据类型的转换
    通过 Parameter 对象添加 Ajax 请求时的参数
    在 jQuery Repeater 进行验证更新等操作时提示消息
    jquery repeater 模仿 Google 展开页面预览子视图
    在 jQuery Repeater 中检索过滤数据
    功能完善的 jquery validator 完成用户注册的验证
    在 Repeater 中绑定转化 JSON 格式的字段
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5382429.html
Copyright © 2011-2022 走看看