# Dilworth theorem learning notes

Posted by alsal on Thu, 23 Sep 2021 14:18:17 +0200

Yesterday, you got dilworth theorem in t2 Middle School of membrane competition. I felt a little wonderful, so I simply studied it

1. Introduction: first review yesterday's film game t2

The main idea of the question is that given n tuples (x,y), the two tuples of X1 < = x2 and Y1 < = Y2 can be divided into one pile. How many piles can be divided at least

Idea: after sorting all the binary units from large to small by x, just look at how many non rising subsequences y can be divided into

The problem is, how to find the minimum partition number?

——Dilworth's theorem is on the stage

2. What is dilworth theorem?

Dilworth's theorem, also known as the decomposition theorem of partially ordered sets, is about Poset The minimax theorem asserts that for any finite element Poset , its maximum Anti chain The number of elements in must be equal to the number of chains in the minimum chain partition. The dual form of this theorem is also true. It asserts that for any finite partially ordered set, the number of elements in its longest chain must be equal to the number of anti chains in its minimum anti chain partition. The graph G generated by the partially ordered set P is called the comparable graph of the partially ordered set: the node set of G is composed of the elements of P, and e is the edge in G, only if the two ends of e are comparable in P, The comparable graph of a finite totally ordered set is a complete graph (from Baidu Encyclopedia)

(it can be easily understood as: minimum score = maximum anti chain length)

prove:

theorem   For posets < A, ≤ >, let the len gt h of the longest chain in a be n, then the elements in a are divided into disjoint inverse chains, and the number of inverse chains is at least n.

Prove that Shi is induced in n.

When n=1, A itself is an inverse chain, and the conclusion of the theorem holds. (in this case, ≤ is an identity relationship).

It is assumed that the conclusion is valid for n=k. Considering the case of n=k+1, when the length of the longest chain in a is k+1, let m be the set of maximal elements in a, and it is obvious that M is an inverse chain. And the length of the longest chain in A-M is K. According to the inductive hypothesis, A-M can be divided into at least k disjoint anti chains. With the addition of anti chain m, a can be divided into at least k+1 anti chains. (from Baidu Encyclopedia)

Therefore, for the question just now, only the longest ascending subsequence is required

```#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,f[100005],a[100005],len,x[100005],xx,yy,cnt;
struct node{int x,y;}b[100005];
bool cmp(node a,node b){
if(a.x!=b.x)return a.x>b.x;
else return a.y>b.y;
}
bool vis[1005][1005];
signed main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld%lld",&xx,&yy);
if(!vis[xx][yy]){
b[i].x=xx;b[i].y=yy;
vis[xx][yy]=1;
cnt++;
}
}n=cnt;
sort(b+1,b+1+n,cmp);
for(int i=1;i<=n;i++)a[i]=b[i].y;
for(int i=1;i<=n;i++){
if(len==0||a[i]>x[len]) x[++len]=a[i];
else{
int l=1,r=len;
while(l<r){
int mid=(l+r)>>1;
if(a[i]<=x[mid]) r=mid;
else l=mid+1;
}
x[l]=a[i];
}
}
printf("%lld\n",len);
return 0;
}```

3. Typical examples

Give n cows, given the initial position (different and ensure ascending input), the speed of each cow, and find the minimum number of runways to ensure that overtaking will not occur

Analysis: firstly, since the initial positions are different and in ascending order, if the end position is in reverse order after t time, it indicates that there is overtaking in the process. Therefore, the essence of this problem is to score the minimum ascending subsequence of the end position, which can be transformed into finding the longest non ascending subsequence according to dilworth theorem

```#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[1000005],c[1000005],len,p,n,t,v;
signed main(){
scanf("%lld%lld",&n,&t);
for(int i=1;i<=n;i++)scanf("%lld%lld",&p,&v),a[i]=p+v*t;
for(int i=n;i>=1;i--){
if(len==0||a[i]>=c[len])c[++len]=a[i];
else{int t=upper_bound(c+1,c+len+1,a[i])-c;
c[t]=a[i];
}
}
printf("%lld\n",len);
return 0;
}```
```#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[1005][1005],f[1005][1005],t,n,m;
signed main(){
scanf("%d",&t);
while(t--){
memset(f,0,sizeof(f));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
f[i][j]=max(max(f[i-1][j],f[i][j+1]),f[i-1][j+1]+a[i][j]);
}
}
printf("%lld\n",f[n][1]);
}
return 0;
}```

Topics: C++ Algorithm linear algebra