Codeforces811C. Vladik and Memorable Trip

微软登录OAuth 2.0授权流程 OAuth 2.0是一个关于授权的开放网络标准,它允许第三方应用获取用户数据,是目前最流行的授权机制。微软身份平台支持OAuth 2.0授权码流程,使得客户端应用程序能够获得对受保护资源(如网络API)的授权访问。这一流程在保障用户数据安全的前提下,实现了应用的便捷登录与数据共享。当用户在一个支持OAuth 2.0的应用上,希望使用微软账号进行登录时,OAuth 2.0授权流程即被触发。 阅读详情

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;
    }
}
深度学习笔记(3)——kernel(内核)与filter(滤波器) 本文仅仅简单介绍了kernel和filter的概念,介绍了确定filter和kernel个数的方法。 阅读详情

相关推荐

数模【Mathematica(安装、入门方法、基本计算、基本图形、创建互动模型、利用数据、幻灯片演示、完整实例)】

Mathematica(安装and激活、入门方法、基本计算、基本图形、创建互动模型、利用数据、幻灯片演示、完整实例) Mathematica_11.3.0 安装教程 Mathematica11.3 激活 P1 笔记本 P2 入门方法 P3 基本计算 P4 基本图形 P5 创建互动模型 P6 利用数据 P7 演示 P8 完整实例

upward 12万+

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

无人驾驶小车调试笔记(六)-- 车轮校准

简介:小车的动力完全来自于两个电机带动的车轮,在理想状态下,给两个电机同样的驱动参数,两个车轮会以同样的转速带动小车直线行驶,而实际情况是每个电机可能都会有个体差异,也就是说给予同样的驱动参数,表现出的转动速度会有些许不同,两个轮子的差速会导致车辆拐弯,后果就是给了直线行驶的控制命令,但是车走着走着就偏离了原本的方向,所以在开始控制之前,我们需要先平衡两个车轮的转速,保证在同样驱动参数下,两个车轮转速大致相同,也就是可以走直线。 车轮校准分为3步,测试、调整后再测试、保存参...

aibingjin的博客 1820

Vladik and Memorable Trip

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

天真有邪的博客 362

tmux + Claude Code 远程开发指南:从 WSL 配置到断线无忧

远程开发中,SSH 连接中断常导致后台任务丢失,这是困扰开发者的经典难题。tmux 作为终端复用器,通过将进程挂在常驻会话中,使其脱离 SSH 连接独立运行,从根本上解决了断线导致的任务终止问题。Claude Code 等 AI 编程代理需要长时间运行并保持交互上下文,恰好依赖这种会话持久化能力。结合 Windows Subsystem for Linux 提供类 Unix 环境,开发者可在 Windows 上实现稳定的远程开发工作流。本文将完整介绍从 WSL 环境配置、tmux 会话管理,到与 Claud

weixin_30423065的博客 348

用Multisim和74192芯片复刻经典:手把手教你搭建篮球24秒违例计时器(附仿真文件)

本文详细介绍了如何使用Multisim仿真平台和74192芯片构建篮球24秒违例计时器,涵盖时序逻辑电路设计、核心器件选型、仿真环境搭建及调试技巧。通过分步指导,帮助读者掌握数字电路设计的关键技术,并附赠仿真文件供实践参考。

weixin_27014595的博客 278

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

从LLM到VLM再到VLA:三兄弟的“变形记”——定义、架构演进与最新趋同

LLM、VLM、VLA虽然在时间上依次出现,但它们在架构上的演进并非线性替代,而是形成了一个从“理解语言”到“理解世界”再到“改变世界”的认知闭环。VLA之所以能在短短三年内从概念走向现实,正是因为它站在了LLM和VLM的肩膀上——RT-2的泛化能力来自互联网规模的VLM预训练,π0的扩散策略受益于生成式模型的突破,Helix的双系统架构借鉴了“快慢思考”的认知科学洞见。而反过来,VLA在实际部署中遇到的效率瓶颈和实时性要求,也在倒逼LLM和VLM向更轻量、更高效的架构方向演进。

Ven%的博客 490

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

uniapp - 实现APP后台持续定位+手机息屏后能持续上传位置信息数据,详解后台保活持续运行+手机锁屏保证后台持续/实时定位的解决方案及示例源码(完美兼容安卓android与苹果ios系统手机)

使用uniapp开发app实现后台保活定位能力,uniapp实时定位保活 息屏定位后台运行,uniapp APP实时定位高德 后台运行 支持锁屏息屏运行,持续获取定位信息,uniapp App端后台间隔时间发送定位功能实现,UniApp实现手机应用常活,固定时间内上传手机位置信息,后台(或锁屏)持续/实时定位的实现方案,uni-app后台持续定位,锁屏后能持续上传位置信息,实现后台定位持续无限制定位高德定位,百度定位,UniApp后台持续定位保如何在APP退到后台时保持定位服务,uniapp 切换app仍能

🏆 前端领域优质创作者 1万+

零基础速成simulink代码生成——stateflow基础3

此专栏面向嵌入式工程没有matlab开发经验的人,可以快速学习和实践这门技术。MDB技术,越来越成熟和普遍,从手写代码转到基于模型开发已经是大势,不仅减少开发周期,还增加代码的复用性。汽车领域、医疗和算法建模广泛使用。

不断debug,优化中…… 1711

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

ansys license许可证问题:Ansys License Manager Release 2024 R1...如何解决?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 5369

CodeForces 811C Vladik and Memorable Trip

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

SKT T2的博客 173

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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
上一篇: 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、付费专栏及课程。

余额充值