题意:求二维偏序的最少链划分。

用到Dilworth定理:最少链划分=最长反链。(对偶也成立,个人认为区别只是一个维度上的两个方向,写了个简单的证明

相关概念:偏序集,链,反链等等概念可以参考这里:http://www.cnblogs.com/fstang/archive/2013/03/31/2991220.html

Dilworth定理的证明(英文的):http://aleph.math.louisville.edu/teaching/2009FA-681/notes-091119.pdf

证明

简要来说,设链的最小划分数为p,最长反链长度为l,证明分两步:

(1).p≥l。因为反链上任意两点都不可能在同一个链中,抽屉原理可知p≥l。

(2).p≤l。反复选择反链的极小元点集Xi从全集S中删除直到S为空,

每次阶段的选择的Xi则构成一个链划分(这个可以反证,如果Xi存在a和b无法比较,那么反链中是可比的,则a和b不可能同时是反链的极小元)

最后一次删除将会对应最长的反链。所以链划分了l次,而p是最小链划分,所以有l≥p。

至于实现上,我采用的是O(nlogn)的逆向求LIS的方法来得到最长反链的。

(似乎根据证明第二步可以得出贪心做法,不过因为要排序时间复杂度还是O(nlogn)。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std; const int N = 5e3+; struct Stick
{
int l, w;
bool operator <(const Stick &th) const{
return l < th.l || (l == th.l && w < th.w);
}
void IN(){ scanf("%d%d",&l,&w); }
}stick[N]; int g[N]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; cin>>T;
while(T--){
int n; scanf("%d",&n);
for(int i = ; i < n; i++){
stick[i].IN();
}
sort(stick,stick+n);
memset(g,0x3f,sizeof(int)*n);
int ans = ;
for(int i = n-; i >= ; i--){
int k = lower_bound(g+,g+n-i,stick[i].w)-g;
ans = max(ans,k);
g[k] = stick[i].w;
}
printf("%d\n",ans);
}
return ;
}

POJ 1065 Wooden Sticks(LIS,最少链划分)的更多相关文章

  1. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

  2. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  3. HDU ACM 1051/ POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. POJ 1065 Wooden Sticks (贪心)

    There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...

  5. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  6. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  7. poj 1065 Wooden Sticks 【贪心 新思维】

    题目地址:http://poj.org/problem?id=1065 Sample Input 3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1 ...

  8. POJ 1065 Wooden Sticks【贪心】

    题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...

  9. POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)

    题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...

随机推荐

  1. iOS回顾笔记( 01 )-- XIB和纯代码创建应用的对比

    header{font-size:1em;padding-top:1.5em;padding-bottom:1.5em} .markdown-body{overflow:hidden} .markdo ...

  2. lynis检测

    https://www.cnblogs.com/ssooking/p/6034402.html Usage: lynis command [options] Command: audit audit ...

  3. 关于STL库中的max min swap

    嗯...   不得不说c++中的STL库是一个神奇的东西   可以使你的代码显得更加简洁....   今天就只讲STL中的三个鬼畜:   max       min       swap   具体操作 ...

  4. POJ1010 Stamps

    题目来源:http://poj.org/problem?id=1010 题目大意: 某邮局要设计新的邮资管理软件,依据顾客的需要和现有的面值给顾客分派邮票. 该邮局有很多顾客是集邮爱好者.这些人希望得 ...

  5. BZOJ4552(二分+线段树)

    要点 序列是n个不同的数,则新学到的一种策略就是二分这个位置的答案,然后可以上下调. 神奇地只关注大于还是小于mid并赋值0.1,这样m个操作的排序就能用线段树维护了! #include <cs ...

  6. Python 起步 环境配置

    1:https://www.python.org/   首先进入这个网址,选择自己喜欢的版本 2:嘛,我以前装的是2.7,把下载好的安装一下就行  3:我的电脑Python的安装路径C:\Progra ...

  7. Codeforces Round #365 (Div. 2) B

    Description Little Mishka is a great traveller and she visited many countries. After thinking about ...

  8. maven参数

    mvn clean package -DskipTests mvn -T 2 clean install/mvn -T 2C clean install: maven支持并行构建,-T 2表示使用2个 ...

  9. spring静态工厂方法得到单例bean

    import org.springframework.beans.BeansException; import org.springframework.context.ApplicationConte ...

  10. Docker从入门到实战(四)

    Docker基础 一:Docker基本操作 一般情况安装Docker之后系统会自动创建一个Docker的用户组,如果没有创建可以手动创建groupadd docker把当前非root用户加入group ...