题目大意
给出一个园,圆上有100个点,若干条弦,让你选择尽量多互不相交的弦(点可以重合)
解题思路
可以把圆展开成链,然后复制一遍
设fi,jf_{i,j}fi,j为第i个位置到第j个位置的所选弦的数量
那么可以枚举中间点,然后区间DP
代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define N 210
using namespace std;
int n, x, y, ans, a[N][N], f[N][N];
int main()
{scanf("%d", &n);for (int i = 1; i <= n; ++i){scanf("%d%d", &x, &y);if (x > y) swap(x, y);a[x][y] = 1;a[x + 100][y + 100] = 1;}for (int len = 2; len <= 100; ++len)for (int i = 1; i <= 200 - len + 1; ++i){int j = i + len - 1;for (int k = i; k <= j; ++k)f[i][j] = max(f[i][j], f[i][k] + f[k][j]);//从小区间转移到大区间f[i][j] = f[i][j] + a[i][j];//新区间的边}for (int i = 1; i <= 100; ++i)ans = max(ans, f[i][i + 100 - 1]);printf("%d", ans); return 0;
}