https://www.acwing.com/solution/content/10173/
问一个序列最少用多少不上升序列能恰好覆盖
Dilworth定理:对于一个偏序集,最少链划分等于最长反链长度。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, t, a[1010],dp[1010],f[1010],ans,cnt;
int main()
{
while(cin >> t ) a[n] = t,f[n] = 1,dp[n++]=1;
for(int i = 1; i < n; i++)
{
for(int j = i-1; j >= 0; j--)
{
if(a[i] <= a[j]) f[i] = max(f[i], f[j]+1);
if(a[i] > a[j]) dp[i] = max(dp[i], dp[j]+1);
}
ans = max(ans,f[i]);
cnt = max(cnt,dp[i]);
}
cout << ans << endl << cnt << endl;
return 0;
}