Codeforces811C. Vladik and Memorable Trip

一、C++反作弊对抗实战 (基础篇 —— 2.注册表注入DLL) 在Windows NT/XP操作系统中,当需要加载user32.dll的程序启动时,user32.dll会加载注册表键HLM\Software\Microsoft\WindowsNT\CurrentVersion\Windows\AppInit_dlls下面列出的所有模块。 阅读详情

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;
    }
}
BES 平台 SDK之 美格信Dongle 连接 最近项目到了试产阶段,需要用到美格信的Dongel 来测试ANC 相关功能。在此简单介绍下如何连接Dongel 的操作步骤。 阅读详情

相关推荐

基于Labview2012实现的双通道信号源(课程设计)

双通道信号源,产生8种波形,能进行调制,带信号幅度与频率扫描功能,波形可存储与导入

qq_40617082的博客 1461

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

5分钟搞定:用Pyannote和Whisper实现带说话人分离的语音转文字(附完整代码)

本文详细介绍了如何快速构建一个集成了说话人分离功能的语音转文字系统。通过结合OpenAI的Whisper模型进行高精度语音识别和Pyannote模型实现说话人分离,并提供了完整的代码实现、环境搭建指南以及核心的对齐与合并逻辑,帮助开发者高效处理会议录音、访谈等多说话人音频,实现自动化转录。

threejs5artist的博客 635

Vladik and Memorable Trip

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

天真有邪的博客 362

【异常】Milvus向量数据库的常见错误“collection not loaded“(集合未加载)

Milvus数据库报错"collection not loaded"分析及解决方案。该错误发生在对未加载的集合执行查询操作时,核心原因是集合创建后需先加载到内存才能使用。解决方案包括:1)确认集合是否存在;2)查询前调用loadCollection接口加载集合;3)处理加载超时或失败情况,可检查加载状态;4)确保Milvus服务正常运行。建议在长期不使用集合时释放内存资源。文末附Java代码示例说明具体操作方法。

奶爸的编程之路,也就一周冷个三天 380

RK3588开发笔记-PCIE接口2.5G网卡RTL8125调试记录

在RK3588平台上调试2.5G网卡(Realtek RTL8125)时,我们会用到PCIE接口,这篇文章记录了从硬件连接、内核驱动到最终实现网络通信的整个调试过程,包括可能遇到的问题和解决方案。Realtek RTL8125是为高带宽需求设计的一款高性价比2.5G以太网控制器。它不仅提供了高达2.5Gbps的网络传输速率,还具备良好的节能特性、硬件卸载引擎和广泛的操作系统支持。无论是在家庭网络、企业NAS,还是游戏和云计算等场景中,RTL8125都能为用户提供更快速、更稳定的网络连接。

flypig has a dream! 3680

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

第12篇:TMC2240 CoolStep节能功能|软件配置+功耗测试(保姆级)

本文介绍了TMC2240驱动芯片的CoolStep节能功能,通过动态调节电机电流实现功耗优化。CoolStep利用StallGuard技术实时检测负载,自动调整运行电流,空载时可降低50%以上功耗。文章详细讲解了节能原理、寄存器配置方法和参数校准步骤,提供可直接复用的STM32代码。该功能特别适合电池供电设备,能显著延长续航时间,同时保持电机性能稳定。配置时需注意SG阈值、电流步长等关键参数,并可与静音模式叠加使用。

BackCatK Chen的博客 918

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

GitLab CI/CD .gitlab-ci.yml 关键词(十一):发布版本 release

本篇文章介绍使用GitLab CI/CD 发布一个版本,对外发布。并填写一些发布的信息。

知无涯 4719

使用 Simulink + Simscape Electrical 实现一个三相电压型PWM整流器的仿真模型

三相电压型PWM整流器(Voltage Source PWM Rectifier, VSR)是一种先进的电力电子装置,它不仅可以将交流电转换为直流电,还能实现单位功率因数操作,即输入电流与输入电压同相位。这不仅提高了电网质量,减少了谐波污染,而且提高了整个系统的效率。本文将详细介绍如何使用实现一个三相电压型PWM整流器的仿真模型,并探讨其在单位功率因数下的控制策略和仿真结果。本文详细介绍了如何使用搭建一个三相电压型PWM整流器的仿真模型,并对其在单位功率因数下的控制策略进行了探讨。

amy_mhd的博客 128

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

python实现MACD策略背离点的判断 (附完整源码)

python实现MACD策略背离点的判断 (附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 665

CodeForces 811C Vladik and Memorable Trip

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

SKT T2的博客 173

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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

余额充值