HDU4876ZCC loves cards(多校题)

HDU4876ZCC loves cards(多校题)

大家好,又见面了,我是全栈君。

ZCC loves cards

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

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

题意:给n个数。从中选出k个数,这k个数能够随意排列,一旦定了顺序就不能改变,在这个确定的顺序。选出m(m<=k)个数异或得到的值x,在这个顺序得到的全部x的值中找出一个最大值R,这些数中使得存在一个连续的范围L~R。

#include<stdio.h>
#include<string.h>
int n,k,L,ans[25];
int a[13],aa[13],R,flag[150];
int vist[10];
void find(int tk)
{
    if(tk==k-1)
    {
        memset(flag,0,sizeof(flag));
        for(int i=0;i<k-1;i++)
        a[i+k]=a[i];
        int maxa=0;
        for(int i=0;i<k;i++)//枚举一个确定序列的连续片断的异或值
        {
            int x=a[i]; flag[x]=1; if(maxa<x)maxa=x;
            for(int j=i+1;j-i+1<=k;j++)
            {
                x^=a[j]; flag[x]=1;if(maxa<x)maxa=x;
            }
        }
        int r=0;
        for(int i=L;i<=maxa;i++)//找出这个最大值R,使得这些数存在L~R范围的数都存在。
        if(flag[i]==0)break;
        else r=i;
        if(r>R)R=r;
        return ;
    }
    tk++;
    for(int i=0;i<k;i++)
    if(vist[i]==0)
    {
        a[tk]=aa[i]; vist[i]=1; find(tk); vist[i]=0;
    }
}
bool panduan()//放宽条件(随意顺序)推断
{
    memset(flag,0,sizeof(flag));
    int maxa=0;
    for(int i=1;i<(1<<k);i++)
    {
        int x=0;
        for(int j=0;(1<<j)<=i;j++)
        if((1<<j)&i)x^=aa[j];
        flag[x]=1;
        if(maxa<x)maxa=x;
    }
    int r=0;
    for(int i=L;i<=maxa;i++)
    if(flag[i]==0)break;
    else r=i;
    return r>R;
}
void CNM(int tk,int i)
{
    if(tk==k-1)
    {
        if(panduan())
        find(-1);
        return ;
    }
    tk++;
    for(int j=i+1;j<n;j++)
    {
        aa[tk]=ans[j]; CNM(tk,j);
    }
}
int main()
{
    while(scanf("%d%d%d",&n,&k,&L)>0)
    {
        R=0; memset(vist,0,sizeof(vist));
        for(int i=0;i<n;i++)
        scanf("%d",&ans[i]);
        CNM(-1,-1);
        printf("%d\n",R);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116456.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Flash与页面交互的钥匙之 AllowScriptAccess

    Flash与页面交互的钥匙之 AllowScriptAccess原文:http://cloud21.iteye.com/blog/729676今天为一个flash的问题搞了半天,flash在页面中点不开js的提示框,如果单是这一个问题,那我立刻就能确定问题所在,一

    2022年7月2日
    24
  • Centos7 安装nginx1.16.0[通俗易懂]

    Centos7 安装nginx1.16.0[通俗易懂]一、环境配置nginx使用C语言进行开发,建议在linux环境下运行,本文只介绍linux下的安装1、gcc安装安装nginx需要先将官网上的源码下载下来进行编译,编译依赖gcc环境,如果系统中未装有gcc,则需要进行安装。执行如下命令安装gcc环境:yuminstallgcc-c++2、pcrepcre-devel安装PCRE(PerlCompatibleRegu…

    2022年6月9日
    32
  • pycharm代码特效插件_pycharm插件在哪

    pycharm代码特效插件_pycharm插件在哪相信对于不少的Python程序员们都是用Pycharm作为开发时候的IDE来使用的,今天小编来分享几个好用到爆的Pycharm插件,在安装上之后,你的编程效率、工作效率都能够得到极大地提升…

    2022年8月27日
    2
  • RDLC——画图表

    RDLC——画图表我们接着上一篇博文接下来我们来画一个柱形图我们就先默认选择第一个柱形图然后这里很关键 有人问 我这里的数据和我下面添加的姓名年龄数据不一样怎么办 一步一步来 我们先再添加一个 datatable 接着返回 report1 rdlc 修改一下表达式 course 也设定一下然后返回 form1 cs 添加的部分红色框起来了 privatevoidF Load objectsender Event

    2025年11月5日
    2
  • SPSS聚类分析「建议收藏」

    SPSS聚类分析「建议收藏」聚类分析是根据对象的特性对其进行定量分类的一种多元统计方法。比如:不同地区城镇居民收入和消费状况的分类研究;区域经济及社会发展水平的分析及全国区域经济综合评价…….通常聚类分析分为Q型聚类

    2022年7月2日
    28
  • 解决eclipse代码自动补全功能默认给变量名添加一些后缀的问题,比如String类型变量名默认添加String后缀

    解决eclipse代码自动补全功能默认给变量名添加一些后缀的问题,比如String类型变量名默认添加String后缀eclipse关闭String变量名添加String后缀问题1.问题2.解决方案1.问题1.问题说明和图示:设置了代码自动补全功能之后,每次新建String类型的变量,输入==空格、;==的时候都会给变量名补上一个String后缀,太多余。2.以下是设置代码自动补全图解1.通过Window》Preferences,进入偏好设置。2.先复制以下代码块中的内容。通过搜索ContentAssist(不分大小写)关键字,找到对应选项,填入.后面保存即可生效。_abcdefghijklmnopq

    2022年5月31日
    33

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号