比赛 SYOI2022 Round2 评测结果 WWWTTTTTTT
题目名称 Looking for Order 最终得分 0
用户昵称 HeSn 运行时间 35.082 s
代码语言 C++ 内存使用 5.74 MiB
提交时间 2022-06-15 20:30:57
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int xt, yt, n, ans = 0, x[50], y[50];
bool ok[50] = {0};
int dfs(int xn, int yn, int num, int dis, int last, int apk = 0) {
	if(last == 0) {
		int sum = (xn - xt) * (xn - xt) + (yn - yt) * (yn - yt);
		ans = max(ans, dis + sum);
		return 0;
	}
	if(num == 2) {
		int sum = (xn - xt) * (xn - xt) + (yn - yt) * (yn - yt);
		dfs(xt, yt, 0, dis + sum, last);
		return 0;
	}
	for(int i = 1; i <= n; i ++) {
		if(ok[i] == 0) {
			ok[i] = 1;
			int sum = (xn - x[i]) * (xn - x[i]) + (yn - y[i]) * (yn - y[i]);
			dfs(x[i], y[i], num + 1, dis + sum, last - 1);
			ok[i] = 0;
		}
	}
	if(apk > n) {
		return 0;
	}
	int sum = (xn - xt) * (xn - xt) + (yn - yt) * (yn - yt);
	dfs(xt, yt, 0, dis + sum, last, apk + 1);
	return 0;
}
int main() {
	freopen("lenepack.in", "r", stdin);
	freopen("lenepack.out", "w", stdout);
	cin >> xt >> yt >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> x[i] >> y[i];
	}
	dfs(xt, yt, 0, 0, n);
	cout << ans << endl;
	return 0;
}