异或Prim。
没开long long WA了一次你敢信?
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 2010
#define INF 0x3f3f3f3f
using namespace std;
int points;
int src[MAX];
int f[MAX];
bool v[MAX];
long long Prim()
{
long long re = 0;
for(int i = 1; i <= points; ++i) {
int max_length = 0, p = 1;
for(int j = 1; j <= points; ++j)
if(!v[j] && f[j] > max_length)
max_length = f[j], p = j;
v[p] = true;
re += max_length;
for(int j = 1; j <= points; ++j)
if(!v[j])
f[j] = max(f[j], src[p]^src[j]);
}
return re;
}
int main()
{
cin >> points;
for(int i = 1; i <= points; ++i)
scanf("%d", &src[i]);
cout << Prim() << endl;
return 0;
}
BZOJ 3943 Usaco2015 Feb SuperBull Prim
原文地址:http://blog.csdn.net/jiangyuze831/article/details/44961687