Codeforces811C. Vladik and Memorable Trip

YOLOv8中间特征层可视化 在通过观察这些特征,可以清楚地看到模型如何逐步将输入图像转化为有意义的表示。 阅读详情

Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:

Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is known (the code of the city in which they are going to).

Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city x, then all people who are going to city x should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city x, either go to it and in the same railway carriage, or do not go anywhere at all.

Comfort of a train trip with people on segment from position l to position r is equal to XOR of all distinct codes of cities for people on the segment from position l to position r. XOR operation also known as exclusive OR.

Total comfort of a train trip is equal to sum of comfort for each segment.

Help Vladik to know maximal possible total comfort.

Input
First line contains single integer n (1 ≤ n ≤ 5000) — number of people.

Second line contains n space-separated integers a1, a2, …, an (0 ≤ ai ≤ 5000), where ai denotes code of the city to which i-th person is going.

Output
The output should contain a single integer — maximal possible total comfort.

Examples
input
6
4 4 2 5 2 3
output
14
input
9
5 1 3 1 5 2 4 2 5
output
9
Note
In the first test case best partition into segments is: [4, 4] [2, 5, 2] [3], answer is calculated as follows: 4 + (2 xor 5) + 3 = 4 + 7 + 3 = 14

In the second test case best partition into segments is: 5 1 [3] 1 5 [2, 4, 2] 5, answer calculated as follows: 3 + (2 xor 4) = 3 + 6 = 9.

这题感觉还是曼坑的。。。我的思路是把每个数字看成一段区间,然后这段区间取还是不取,这段区间的权值是这个区间内不同数字的异或值。然后根据每个区间的左右端点 sort一下去dp。dp[i]表示取i这个区间可以取到的最大值,那么对每个满足转移条件的j 即 s[i].l > s[j].r 可以做一次dp[i] = max(dp[i],dp[j]+s[i].value) 我一开始A不了,后来想明白了。

对 54353对这个区间 我一开始的处理是对5这个数字分配到的区间是0-3,但是我们在区间里取了3,所以我们还要把外面那个3加进来,对于5这个数字他的实际区间应该是0-4。所以我们在预处理完区间之后再扩展一次区间,然后正常做就可以了。
//thanks to qhl ❤

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;

//thanks to pyf ...
//thanks to qhl ...

#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int, int> PII;
typedef long long ll;

const int N = 1e6 + 5;

struct Node
{
    int l, r;
    int value;
} s[10000];
int a[10000];
int vis[10000];
int dp[10000];
bool cmp(Node a, Node b)
{
    return a.r < b.r || (a.r == b.r && a.l < b.l);
}
int main()
{
    int n;
    while (cin >> n)
    {
        int cnt = 0;
        memset(dp, 0, sizeof(dp));
        map<int, int>m;
        m.clear();
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
            if (!m.count(x))
            {
                m[x] = cnt ++;
                s[m[x]].l = i;
                s[m[x]].r = i;
            }
            else
            {
                s[m[x]].l = min(s[m[x]].l, i);
                s[m[x]].r = max(s[m[x]].r, i);
            }
        }
        for (int i = 0; i < cnt; i++)
        {
            for (int j = s[i].l ; j <= s[i].r; j++)
            {
                s[i].l = min(s[m[a[j]]].l, s[i].l);
                s[i].r = max(s[m[a[j]]].r, s[i].r);
            }
        }
        for (int i = 0; i < cnt; i++)
        {
            memset(vis, 0, sizeof(vis));
            s[i].value = 0;
            for (int j = s[i].l; j <= s[i].r; j++)
            {
                if (!vis[a[j]])
                {
                    s[i].value ^= a[j];
                    vis[a[j]] = 1;
                }
            }
        }
        sort(s, s + cnt, cmp);
        for (int i = 0; i < cnt; i++)
        {
            dp[i] = s[i].value;
            for (int j = 0; j < i; j++)
            {
                if (s[i].l > s[j].r)
                    dp[i][1] = max(dp[j] + s[i].value, dp[i]);
            }
        }
        int ans = 0;
        for (int i = 0; i < cnt; i++)
            ans = max(ans, dp[i]);
        cout << ans << endl;
    }
}
OpenCV计算机视觉实战(3)——计算机图像处理基础 本文全面介绍了计算机视觉和数字图像处理的基础知识。从最基本的像素概念入手,详细讲解了图像在计算机中的表示方式,包括RGB、CMYK等色彩空间的工作原理及其应用场景。还系统分析了常见图像和视频文件格式的特点,梳理了计算机图像处理技术的发展历程,并重点介绍了OpenCV这一强大的开源计算机视觉库的功能与应用领域。 阅读详情

相关推荐

Python实战:用Realsense D435和睿尔曼机械臂完成手眼标定的5个关键步骤

本文详细介绍了使用Python、Realsense D435深度相机与睿尔曼机械臂进行手眼标定的完整实战流程。文章将过程拆解为环境搭建、数据采集、核心计算、结果验证和精度优化五个关键步骤,重点剖析了数据采集的黄金法则、常见错误排查以及如何将标定结果集成到视觉抓取程序中,旨在帮助开发者实现毫米级精度的视觉引导机器人系统。

weixin_29103191的博客 320

Codeforces 811C - Vladik and Memorable Trip(预处理 + dp)

Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined

在读NLP硕士 317

【论文分享】【Agent】ProAgent: Building Proactive Cooperative Agents with Large Language Models

多智能体系统是由多个智能体组成的集合,这些智能体可以是软件程序、机器人、传感器或其他实体,它们各自具备一定的智能和自主性,并通过交互协作来实现单个智能体难以完成的复杂目标。

nanxun___的博客 1122

Vladik and Memorable Trip

Vladik and Memorable Trip 题意:给定一个数列,划分一些区间,规定该区间里面包括该区间出现的所有数字,该区间的贡献是区间里面不同数的异或和,答案是求能划分的最大值。 思路:dp,dp[i]表示从1到i划分所能取到的最大值,维护每个数的左右边界即可。 #include<bits/stdc++.h> using namespace std; ...

天真有邪的博客 362

URDF模型转换实战:解决SolidWorks到Gazebo的五大常见问题

本文详细解析了从SolidWorks导出URDF模型到Gazebo仿真过程中常见的五大问题及解决方案,包括插件安装、坐标系建立、Link与Joint配置等关键步骤。通过实战经验分享,帮助机器人仿真工程师高效完成模型转换,确保Gazebo仿真准确性。

weixin_29052717的博客 445

【js逆向学习】新手视角破解「广东省公共资源交易平台」

学习js逆向,破解广东省公共资源交易平台,详细记录个人探索、踩坑全过程。网站地址: aHR0cHM6Ly95Z3AuZ2R6d2Z3Lmdvdi5jbi8jLzQ0L2p5Z2c=仅供学习参考,如有疑问欢迎交流,一起学习进步。

DCSDA的博客 3316

codeforces811C——Vladik and Memorable Trip(动态规划)

C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains

say_c_box的博客 1933

抖音用户评论和ID的采集方法

随着5G时代的普及,各大运营商的套餐纷纷推出,使得流量成本进一步降低。同时5G线路高宽带、低延迟的技术特性和手机普及,让视频用户访问量快速增加。 由于大量的视频工具和拍摄APP的提供,让短视频的拍摄、制作包括发行都变得更加简单便捷,越来越多的普通人可以投入视频创作,创造了更丰富的互联网内容,视频作者从视频推广中能获取粉丝和推广收益。 目前抖音就是目前最重要的短视频平台之一,要及时获取上面的用户评论和ID,需要结合爬虫代理实现采集方案,下面的代码就能快速采集相关信息: package htmlunit; i

ssbt_2020的博客 6787

C. Vladik and Memorable Trip

C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains

樱花满地集于我心,楪舞纷飞祈愿相随 1129

美团mtgsig 3.1.0算法还原:从加密入口到d1生成的完整链路拆解

本文详细拆解了美团mtgsig 3.1.0签名算法的完整逆向过程。通过定位加密入口函数eH,理清a6、a5、a8到d1的生成依赖链,并运用插桩技术,在JSVMP混淆环境下逐步还原了核心参数的生成逻辑,为逆向工程实践提供了清晰的纯算还原方法论。

oo7890的博客 777

某勾网之登录过程逆向

拉勾网的登录过程逆向,包含请求头(X-S-HEADER、X-K-HEADER、X-SS-REQ-HEADER等) 以及 请求参数/返回数据的加解密。

shanf7921的博客 3万+

CF811C:Vladik and Memorable Trip(dp)

C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains

junior19的博客 996

YOLO26改进策略【Neck】| arXiv 2025 分层多头注意力HMHA 子空间拆分提多样 + 通道重排降冗余,强化目标检测精度

HMHA(Hierarchical Multi-Head Attention,分层多头注意力)旨在解决传统多头注意力(MHA)在图像恢复任务中的核心缺陷——特征冗余。传统MHA将通道均匀拆分给各个头,导致不同头学习的子空间信息相似,进而出现多头关注同一区域、忽略退化区域修复的问题,限制了模型的特征表达能力。HMHA通过“分层子空间拆分+通道重排序”策略,让每个头学习差异化、互补的上下文特征,从根源上缓解冗余,提升图像恢复任务中对复杂退化场景的特征捕捉能力。

Limiiiing的博客 210

CodeForces 811C Vladik and Memorable Trip

给定N个数,将它们划分成任意多个区间 要求: 1. 相同的数要么在同一个区间内,要么不在任何区间内; 2. 这段区间的价值 = 不同数(即每一个数若出现多次就只算一次)的异或和 问: 最大价值是多少?

SKT T2的博客 173

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Vladik and Memorable Trip CodeForces - 811C DP

传送门:CodeForces - 811C 题意:给定N个数,将它们划分成任意多个区间,要求:相同的数要么在同一个区间内,要么不在任何区间内。问区间异或和最大是多少。 思路:可以预处理出区间异或值来,也可以动态求,然后dp求一个最大值。 代码:#include #define ll long long #define fi first #define se second #define pi

WA是一笔财富 369

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Codeforces 811C Vladik and Memorable Trip【Dp】

C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains. He remem

mengxiang000000 790

Vladik and Memorable Trip 【CodeForces - 811C】【DP】

题目链接 题目大意 题意有点难读,有点绕: 就是有一个长度为n的序列,要把这个序列分成若干个子串,然后挑选几个子串让他们的异或和最大,相同的数字必须早同一个子串里 解题思路 比赛的时候就知道是个DP,奈何DP差的不忍直视 dp[i]就是1到i直接的子串异或和最大值 每次枚举新加的数可以组成的新的子串更新答案 #include<bits/stdc++.h> using namespace...

qq_41925919的博客 206

Codeforces 811C Vladik and Memorable Trip[dp]

题意:给了一串长度 分析:我们可以先预处理出每个数第一次出现的位置st,最后出现的位置ed,还有区间的异或值sum dp[i] 表示到了 i 之前的序列的答案为多少。 每次在ed的位置转移,判断其中是否有数的ed比现在大,如果大,跳过。没有的话,找其中最小的min_st, dp[i] = min(dp[i-1],dp[min_st - 1] + sum[min_st][i]);

C_z_Q 488

Codeforces 811C Vladik and Memorable Trip DP

点击打开链接 题意:n个数a[i],定义区间[l,r]舒适度为[l,r]内不相同数异或和,要求选出若干条不相交的区间,使得舒适度最大. 要求若a[i]被选中 则所有和a[i]相等的数必须在同一区间 n,a[i] 设dp[i]为前i数能选出的最大值. l(x),r(x)为x第一次和最后一次出现的位置 如果能选a[i]结尾的合法区间即r[a[i]]=i  dp[i]=dp[L-1]+s

Masamiiiiii 451

codeforces 811 C. Vladik and Memorable Trip(dp)

题目链接:http://codeforces.com/contest/811/problem/C 题意:给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都要出现在这个区间。每个区间的价值为该区间不同的数的异或值,现在问你这n个数最大的价值是多少。 题解:一般这种说法的题目都是用dp的,然后显然设dp[i]表示前i个能取得的最大价值,然后再存一下每个数的起始位...

awow80285的博客 177

codeforces 811C Vladik and Memorable Trip

题意:选择n个区间内所有的元素不能在外部出现,求所有各区间内的集合元素异或和? 思路:先预处理可行的区间,然后扫一波即可。 #include #include #include #include #include #include #include #include using namespace std; #define LL long long const

417

CodeForces - 811C Vladik and Memorable Trip

题目来源:http://codeforces.com/problemset/problem/811/C C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input

No cost too great! 295

codeforces 811C C. Vladik and Memorable Trip

http://codeforces.com/problemset/problem/811/C题意: 给一个长度为n的序列,你从中选取若干个区间(不能重叠),并且每个区间内的数只能出现在这个区间里 如 1 2 2 1 你可以选【2,3】,[1,4],不可以选 [1,2],[1,3],[2,4]; 每个区间的权为区间内去重后的异或和,之后区间加和,求最大。思路:用DP求解,预处理出每个数第一

My_stage的博客 487

codeforces 811C Vladik and Memorable Trip[补]

C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by trains. He rem...

weixin_33759269的博客 173

CodeForces-811C Vladik and Memorable Trip

预处理+dp #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #include&lt;cmath&gt; using namespace std; typedef long long ll; const int N=5000+10; int d[N...

wl16wzl的博客 171

[刷题]Codeforces 811C - Vladik and Memorable Trip

哇咔咔,终于期末考完啦,终于放暑假啦,我终于又有时间学习啦!!(o゜▽゜)o☆DescriptionVladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:Vladik is at init

蟹脑板的博客 531

Codeforces 811 C. Vladik and Memorable Trip

C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vladik often travels by tra...

weixin_30587025的博客 101
上一篇: 570D - Tree Requests
下一篇: Codeforces814C. An impassioned circulation of affection
OneDay_pyf
博客等级 码龄10年 6粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值