https://ac.nowcoder.com/acm/contest/317/C
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int a[1000005],maxs=0;
bool vis[1000005];
void dfs(int n) {
memset(vis, false, sizeof(vis));
queue<int> q;
q.push(a[1]);
while (!q.empty()) {
int pre = q.front();
q.pop();
for (int i = 2; i <= n; i++) {
if (a[i] < pre) {
if (i == n) maxs = max(maxs, a[i] ^ pre);
if (i < n && vis[a[i] ^ pre] == false) {
vis[a[i] ^ pre] = true;
q.push(a[i] ^ pre);
}
}
}
}
}
int main()
{
int n;
memset(a, 0, sizeof(a));
while (~scanf("%d", &n)) {
maxs = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
if (a[1] < a[n])
printf("-1\n");
dfs(n);
if (maxs > 0) printf("%d", maxs);
else printf("-1\n");
return 0;
}
}
题意就是让你找一条1到n的路径使得路径上点的异或和最大。
STL不熟练,我要多练练