题解:P3845 [TJOI2007] 球赛
考虑不妨设每个
考虑
注意到我们要求的其实是偏序集上的最小链覆盖,根据 Dilworth 定理知就等价于最长反链。
不妨考虑反链是
范围很小,
注意
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
const int N = 1005;
int n, x[N], y[N], t;
int ans;
pair<int, int> a[N];
int f[N];
int main()
{
scanf("%d", &t);
while (t--)
{
ans = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d-%d", &x[i], &y[i]);
if (x[i] > y[i]) swap(x[i], y[i]);
a[i] = make_pair(x[i], y[i]);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
{
f[i] = 1;
for (int j = 1; j < i; j++)
{
if (a[j].second > a[i].second) f[i] = max(f[i], f[j] + 1);
}
ans = max(ans, f[i]);
}
printf("%d\n", ans);
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现