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)
上一篇 2022年1月21日 上午7:00
下一篇 2022年1月21日 上午8:00


相关推荐

  • python解压bz2文件命令_解压缩bz2文件

    python解压bz2文件命令_解压缩bz2文件bz2.compress/decompress使用二进制数据:>>>importbz2>>>compressed=bz2.compress(b’test_string’)>>>compressedb’BZh91AY&SYJ|i\x05\x00\x00\x04\x83\x80\x00\x00\x82\xa1\x1c\x00\…

    2022年6月5日
    77
  • PHP TCPDF导出支持中文的pdf

    PHP TCPDF导出支持中文的pdfPHP使用TCPDF导出支持中文的pdf一、下载https://github.com/tecnickcom/tcpdf下载TCPDF压缩包二、使用方法 require_once(‘./TCPDF/tcpdf.php’); $pdf=new\TCPDF(); $pdf->AddPage(); $html=”<p>helloworld你好世界</p>”; $pdf->WriteHtml(20,$html); //四种模式I输出

    2025年10月3日
    4
  • 性能指标(模型评估)之mAP

    性能指标(模型评估)之mAP为什么性能指标用于评价模型的好坏 当然使用不同的性能指标对模型进行评价往往会有不同的结果 也就是说模型的好坏是 相对 的 什么样的模型好的 不仅取决于算法和数据 还决定于任务需求 因此 选取一个合理的模型评价指标是非常有必要的 错误率 amp 精度针对数据集 DD 和学习器 ff 而言 1 错误率 分类错误的样本数占总样本的比例 E f D 1m i 1mI f xi yi E f D frac1

    2026年3月19日
    2
  • 深入浅出完整解析即梦AIGC平台的AI技术功能&产品逻辑

    深入浅出完整解析即梦AIGC平台的AI技术功能&产品逻辑

    2026年3月12日
    3
  • HandlerThread原理分析、实战、最佳实践!

    HandlerThread原理分析、实战、最佳实践!本文我们将学习HandlerThread的实现原理,以及开发时,如何正确的使用它来实现我们的开发任务。HandlerThread源码分析设想这样一个场景:我们要在一个线程A中处理业务逻辑,在另一个线程B中,监听A的执行,并进行结果处理。这时我们使用HandlerThread就可以非常简单的实现该功能了。通常我们的线程交互场景,都是UI线程中启动子线程,并且由子线程完成工作任务,最终结果交给UI线程。现在我们的使用场景是,在子线程中监控其他线程的执行结果(这里的其他线程可以是另一个子线程,也可以是UI

    2025年7月15日
    9
  • 数组求和的几种实现方法是什么_js数组求和的方法

    数组求和的几种实现方法是什么_js数组求和的方法例1:一个类直接实现数组求和publicclassAdd{//主类publicstaticvoidmain(Stringargs[]){//主方法intsum=0;//sum保存结果inta[]=newint[]{1,2,3,4};//定义数组for(intx:a){//fo…

    2022年10月2日
    4

发表回复

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

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