比赛 |
EYOI与SBOI开学欢乐赛5th |
评测结果 |
TTTTT |
题目名称 |
最优连通子集 |
最终得分 |
0 |
用户昵称 |
惠惠 |
运行时间 |
5.000 s |
代码语言 |
C++ |
内存使用 |
5.75 MiB |
提交时间 |
2022-09-16 20:57:30 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int N, x[1010], y[1010], c[1010], mem_c, ans = 0;
bool walked[1010] = {0}, plused[1010] = {0};
bool can_walk(int a, int b)
{
if(walked[b]) return false;
if(( max(x[a], x[b]) - min(x[a], x[b]) ) + (max(y[a], y[b]) - min(y[a], y[b]) ) == 1) return true;
else return false;
}
void dfs(int a,int b)
{
// cout << "Now " << a << " to " << b << endl;
if(a == N || b == N) return;
walked[a] = true;
plused[a] = true;
mem_c = c[a];
for(int i = 1; i <= N; ++i)
{
if(can_walk(b, i))
{
walked[i] = true;
if(!plused[i])
{
mem_c += c[i];
plused[i] = true;
}
ans = max(ans, mem_c);
dfs(a, i);
}
}
for(int i = b + 1; i <= N; ++i)
{
walked[i] = false;
plused[i] = false;
}
dfs(a + 1, a + 1);
return;
}
int main()
{
freopen("subset.in", "r", stdin);
freopen("subset.out", "w", stdout);
scanf("%d", &N);
for(int i = 1; i <= N; ++i)
{
scanf("%d%d%d", &x[i], &y[i], &c[i]);
}
dfs(1, 1);
printf("%d", ans);
return 0;
}