hdu1051(LIS | Dilworth定理)

这题根据的Dilworth定理,链的最小个数=反链的最大长度 , 然后就是排序LIS了

链-反链-Dilworth定理

hdu1051

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;
#define N 5050 struct node
{
int x,y;
}g[N]; int cmp(node t,node t1)
{
return t.x<t1.x;
}
int dp[N]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&g[i].x,&g[i].y);
sort(g,g+n,cmp);
memset(dp,,sizeof(dp));
dp[]=;
int ans=;
for(int i=;i<n;i++)
{
int tmp=;
for(int j=;j<i;j++)
{
if(g[j].x==g[i].x) continue;
if(g[j].y>g[i].y) tmp=max(tmp,dp[j]);
}
dp[i]=tmp+;
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}
上一篇:Linux服务器使用Docker部署.net Core项目


下一篇:javascript中with语句应用